Android Intent Chooser to only show E-mail option

Neal picture Neal · Jun 6, 2011 · Viewed 27.1k times · Source

My app integrates e-mail where the user can submit a bug report, feedback, etc. from the app directly. I'm using the application/octet-stream as the SetType for the Intent. When you go to submit the e-mail you get the content chooser and it shows various items from Evernote, Facebook, E-mail, etc.

How can I get this chooser to only show E-mail so as not to confuse the user with all these other items that fit the content chooser type?

Thank you.

Answer

Pedro Varela picture Pedro Varela · Jul 21, 2015

To solve this issue simply follow the official documentation. The most important consideration are:

  1. The flag is ACTION_SENDTO, and not ACTION_SEND.

  2. The setData of method of the intent,

    intent.setData(Uri.parse("mailto:")); // only email apps should handle this

If you send an empty Extra, the if() at the end won't work and the app won't launch the email client.

This works for me. According to Android documentation. If you want to ensure that your intent is handled only by an email app (and not other text messaging or social apps), then use the ACTION_SENDTO action and include the "mailto:" data scheme. For example:

public void composeEmail(String[] addresses, String subject) {
    Intent intent = new Intent(Intent.ACTION_SENDTO);
    intent.setData(Uri.parse("mailto:")); // only email apps should handle this
    intent.putExtra(Intent.EXTRA_EMAIL, addresses);
    intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    }
}

https://developer.android.com/guide/components/intents-common.html#Email