c-an
c-an

Reputation: 4090

how to get the result of Email Intent? the resultCode isn't correct

How can you catch the result of Email Intent?

I tried with this:

val emailIntent = Intent(Intent.ACTION_SEND)
emailIntent.type = "message/rfc822"
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "title")
emailIntent.putExtra(Intent.EXTRA_TEXT, "$sendData")

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

And this doesn't get Activity.RESULT_OK when it sends correctly. Instead, it gets 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
            }
        }
    }

Upvotes: 1

Views: 183

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007266

How can you catch the result of Email Intent?

There is no result. ACTION_SEND has no output.

Upvotes: 1

Related Questions