Issue
I have this simple SENT_TO intent which followed the basic syntax of android intent.
val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, arrayOf("to1","to2"))
putExtra(Intent.EXTRA_SUBJECT, "subject")
putExtra(Intent.EXTRA_TEXT, "text")
}
However, whenever the activity launch, the EXTRA_EMAIL
never pass the value to the recipient. Could someone point me the problem here? (I work with Gmail app)
Solution
Those extras are documented for ACTION_SEND
, not ACTION_SENDTO
. So, already, you're in trouble, as there is nothing requiring an email app developer to pay attention to them.
Beyond that, extras are optional bits of data. Email apps can ignore them, even when they are documented.
Some email clients will pay attention to those extras with ACTION_SENDTO
. I recently found that the now-current version of Gmail does (though I only tested with a single email address, not the two in your question). However, that's not guaranteed across all Gmail versions, let alone across all email apps.
An alternative approach for ACTION_SENDTO
with a mailto:
Uri
is to put the address(es), subject, and body in the mailto:
itself. However, that too is not guaranteed to work.
What's supposed to work is ACTION_SEND
, your extras, an a mailto
selector. That recently started failing to find Gmail, causing me to flip a table (virtually). So, now, I'm using that selector approach, and code reminiscent of your question as a fallback if no activities match the selector Intent
.
Answered By - CommonsWare
Answer Checked By - Marie Seifert (JavaFixing Admin)