Skip to content

Instantly share code, notes, and snippets.



Last active Nov 14, 2015
What would you like to do?
Two ways to open email apps from intent, pre-filling datas. These two methods
// creating the intent with all the information we want to pre-fill
Intent intent = new Intent(Intent.ACTION_SEND);
// array of destination email addresses
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "", "" });
intent.putExtra(Intent.EXTRA_SUBJECT, "my subject");
intent.putExtra(Intent.EXTRA_TEXT, "some message body");
// This type narrows down the amount of apps that will be displayed in the app choice dialog
intent.setType("message/rfc822"); // it should be mostly email apps
// Creating a string URI that will be used to populate the intent's data
String uriText = "" +
"?subject=" + Uri.encode("my subject") +
"&body=" + Uri.encode("some message body"));
// creating a URI out of it
Uri uri = Uri.parse(uriText);
// creating the actual intent
Intent intent = new Intent(Intent.ACTION_SENDTO);
// and setting the URI data

This comment has been minimized.

Copy link
Owner Author

@theyann theyann commented Nov 14, 2015

I have tested these two methods and their are both work at least back to API Level 16, up to level 23.
My personal favorite is the ACTION_SENDTO because the list of proposed apps in the app choice dialog is more refined (only apps that deal with mailto) and there are less possibilities to mess up.
However that being said, the ACTION_SEND method allows for multiple recipients where as the other one does not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.