Skip to content Skip to sidebar Skip to footer

Send An Email In Android Selecting Only Email Apps And Specifying Attachment Mime Type

In my Android App I send email messages with images attached. Using the Intent system to send it, I can do one of the following two things: 1) Specify type as 'message/rfc822' so t

Solution 1:

Cross-posting my answer from the android-developer Google Group:

If you are willing to roll your own dialog, you could:

Step #1: Create the message/rfc822Intent, as if you were going to send that way, and use it with PackageManager and queryIntentActivities() to find out who handles it.

Step #2: Create the image/pngIntent, as if you were going to send that way, and use it with PackageManager and queryIntentActivities() to find out who handles it.

Step #3: Compute the intersection of those two sets of activities.

Step #4: Use those to populate an AlertDialog for the user to choose from.

  • Step #4a: If the intersection has one match, skip this step.
  • Step #4b: If the intersection has zero matches, let the user know you can't send the message.

Step #5: Modify the image/pngIntent to add the component selected from the dialog, and call startActivity() on it.

By specifying the component in the Intent, it will go to that particular activity. This is effectively what the regular chooser does.

Post a Comment for "Send An Email In Android Selecting Only Email Apps And Specifying Attachment Mime Type"