Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email Intent subject is ignored in gmail, but works with other mail clients

For below mentioned code subject is getting displayed in other email accounts but the same is coming blank in gmail.

Intent j = new Intent(Intent.ACTION_SENDTO);
j.setData(Uri.parse("mailto:[email protected]"));
j.putExtra(Intent.EXTRA_SUBJECT, "Request approval for Kiranam Registration - " + KiranamUserId);
startActivity(Intent.createChooser(j, "Select your mail account to send mail for Approval"));
like image 422
Sabir Syed Avatar asked Dec 08 '19 16:12

Sabir Syed


3 Answers

I found that setting the data part of the intent to Uri.parse("mailto:") and defining the email via Intent.EXTRA_EMAIL works fine:

Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:")).apply {
    putExtra(Intent.EXTRA_EMAIL, arrayOf("[email protected]"))
    putExtra(Intent.EXTRA_SUBJECT, "Support request")
    putExtra(Intent.EXTRA_TEXT, "Hello team!")
}
like image 150
ubuntudroid Avatar answered Oct 01 '22 08:10

ubuntudroid


Gmail seems to ignore Intent extras. Try this instead:

Intent j = new Intent(Intent.ACTION_SENDTO);
j.setData(Uri.parse("mailto:[email protected]" +
    "?subject=Request approval for Kiranam Registration - " + KiranamUserId));
j.putExtra(Intent.EXTRA_SUBJECT, "Request approval for Kiranam Registration - " + KiranamUserId);
startActivity(Intent.createChooser(j, "Select your mail account to send mail for Approval"));
like image 27
David Wasser Avatar answered Oct 01 '22 09:10

David Wasser


ACTION_SENDTO is not documented to support any extras. So, while you are welcome to include EXTRA_SUBJECT, do not assume that any particular app responding to ACTION_SENDTO will honor it.

Even for places where extras are documented — ACTION_SEND documents support for EXTRA_SUBJECT, for example — there is no requirement for every app to honor every extra.

like image 25
CommonsWare Avatar answered Oct 01 '22 07:10

CommonsWare