I implemented sending emails from my application.
I used this quesion on SO as a guide to achieve this, note that in the answers someone said to use setType("message/rfc822");
because it filters out all other email client that listen to the ACTION_SEND
intent.
My problem is that my galaxy tab 10.1 still has two application that listen to the intent, so a popup still opens asking me what email client I want to use. (The gMail app or the default eMail app). I can't uninstall one so the list won't popup, but I don't want to either.
Is there a way to force android to just use the first one in the list instantly? So the user can skip the popup dialog?
Here is my current code:
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.notes_from_pf));
i.putExtra(Intent.EXTRA_TEXT , context.getString(R.string.mail_message));
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(context, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
query applications, get a list of applications which are register to send action and choose one, create an intent, set class name and start your intent and you're done
if you wish to find which apps can handle the intent , you can use:
getPackageManager().queryIntentActivities...
when you find the app that you wish , set the package of the intent to match the one of the app.