Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Intent Chooser to only show E-mail option

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.

like image 300
Neal Avatar asked Jun 06 '11 17:06

Neal


People also ask

How do I open Gmail with intent?

Use this: Intent intent = getPackageManager(). getLaunchIntentForPackage("com.google.android.gm"); startActivity(intent);

What is intent setType in Android?

setType(String mimeType) input param is represent the MIME type data that u want to get in return from firing intent(here myIntent instance). by using one of following MIME type you can force user to pick option which you desire. Please take a Note here, All MIME types in android are in lowercase.

What is Android intent Action view?

An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object.


1 Answers

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

like image 84
Pedro Varela Avatar answered Oct 07 '22 15:10

Pedro Varela