首页 > 解决方案 > 如何获得电子邮件意图的结果?结果代码不正确

问题描述

您如何捕获电子邮件意图的结果?

我试过这个:

val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.type = "message/rfc822"
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("xxxx@gmail.com"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "title")
emailIntent.putExtra(Intent.EXTRA_TEXT, "$sendData")

startActivityForResult(Intent.createChooser(emailIntent, "Send mail..."), RESULT_SEND_EMAIL)                                    

当它正确发送时,这不会得到Activity.RESULT_OK。相反,它得到Activity.RESULT_CANCELED.

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == RESULT_SEND_EMAIL) {
            // Make sure the request was successful
            if (resultCode == Activity.RESULT_OK) {
                Toast.makeText(this, "Sending success", Toast.LENGTH_SHORT).show()
            }else{
                Toast.makeText(this, "Sending cancel", Toast.LENGTH_SHORT).show()
                return
            }
        }
    }

标签: androidandroid-intentonactivityresult

解决方案


您如何捕获电子邮件意图的结果?

没有结果。ACTION_SEND没有输出


推荐阅读