I am writing an app that needs to send emails at the end of each transaction. I am doing the following:
Intent mail = new Intent(Intent.ACTION_SEND);
mail.setType("text/html");
mail.putExtra(Intent.EXTRA_EMAIL, new String[] { emailTo });
mail.putExtra(Intent.EXTRA_SUBJECT, "Send from Android");
mail.putExtra(Intent.EXTRA_TEXT, "Sent from Android");
startActivity(Intent.createChooser(mail,"Select Email Software..."));
What I would like to do is pre-select the email software and store it in a setting. That way, every time the email is being sent, it does not have to ask the user which email to use. I just can't seem to figure out how to invoke the chooser and get the selected value.
Any help would be greatly appreciated.
It's a common misconception to use
text/plain
ortext/html
. This will trigger any application that can handle plain or HTML text files without any context, including Google Drive, Dropbox, Evernote and Skype.Instead use a
ACTION_SENDTO
, providing themailto:
Uri:You can then proceed using the chooser as suggested through the other answers.
You would have to create your own chooser, possibly as an
AlertDialog
populated using the results of callingqueryIntentActivities()
onPackageManager
.Here is the solution:
Save the choice for later use:
Now, to consume it, just to the following:
fill in rest of data and start the activity