Email Intent not showing the chooser

2019-01-27 04:26发布

问题:

I'm using the following to initiate the sending of an email:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc882"); 
i.putExtra(Intent.EXTRA_EMAIL, new String[]{s});
startActivity(Intent.createChooser(i, "Send mail..."));

The problem that I'm having is that (on my phone) it pulls up Gmail's Compose window instead of allowing me to choose which email client I'd like to send the message with.

Am I doing this wrong, or does the default email client just not respond to email send intents?

回答1:

It might not respond to message/rfc882 Intents. Try text/plain instead, if you can, as I'm pretty sure that works.



回答2:

It's a common misconception to use text/plain. This will trigger any application that can handle plain text files without any context, including Google Drive, Dropbox, Evernote and Skype.

Instead use a ACTION_SENDTO, providing the mailto: Uri:

intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"));
startActivity(intent);