Send an email to Android by selecting only email applications and specifying the mime type of application

In my Android app, I am sending emails with attached images.

Using the Intent system to submit it, I can do one of the following two things:

1) Specify the type as "message / rfc822" so that ONLY email applications are displayed in Chooser.

Inconvenience: I cannot specify the mime type of the image I am attaching using EXTRA_STREAM and Uri. Many receiving email applications (Gmail, Android, etc.) show this as an unknown blob attached to a message, don’t know how to view it, and don’t know how to open it as an attachment.

2) Specify the type as (say) "image / png". The image is attached, and email clients such as Gmail can view it and open the attachment in the corresponding application.

Inconvenience: for the sending user, I cannot reduce the list of applications that the user must select in Chooser to send email applications, and MANY applications appear on my Android device, most of which are not email applications, and not what I want .

Is it possible to specify his email address "message / rfc822" And specify the MIME type of data connected via Uri in Intent.EXTRA_STREAM?

BTW: I provide a file from my own ContentProvider, and the getType () method (used to determine the type of the MIME file) is NOT called. The query () method, but does not query the file type, displays only the name and size of the file.

thanks

+4
source share
1 answer

Cross-submitting my answer from the Google Android Developer Team :

If you are ready to flip your own dialogue, you can:

Step # 1: Create message/rfc822 Intent , as if you were going to send this path and use it with PackageManager and queryIntentActivities() to find out who processes it.

Step # 2: Create an image/png Intent as if you were going to send this way, and use it with PackageManager and queryIntentActivities() to find out who processes it.

Step # 3: Calculate the intersection of these two sets of actions.

Step # 4: use to populate the AlertDialog for the user.

  • Step # 4a: If the intersection has one match, skip this step.
  • Step # 4b: If the intersection has zero matches, inform the user about this; you cannot send a message.

Step # 5: Change the image/png Intent to add the selected component from the dialog and call startActivity() on it.

By specifying a component in Intent , it will move on to this specific activity. It is effective what regularly chooses does.

+3
source

All Articles