Only Email apps to resolve an Intent

Viewed 28276

I have a problem .. I want only email activities to resolve intent ACTION.SEND but beside email I get other apps as well (e.g TubeMate) even though I have set the mime type as 'message/rfc822' ... Any idea how can I get Email applications to resolve it ..

14 Answers

When I use intent android.content.Intent.ACTION_SENDTO doesn't work for me because it shows many apps, some apps are not email clients. I found this way and it works perfectly for me.

Intent testIntent = new Intent(Intent.ACTION_VIEW);  
Uri data = Uri.parse("mailto:?subject=" + "blah blah subject" + "&body=" + "blah blah body" + "&to=" + "sendme@me.com");  
testIntent.setData(data);  
startActivity(testIntent);

This works for me

Intent intent = new Intent("android.intent.action.SENDTO", Uri.fromParts("mailto", "yourmail@gmail.com", null));
intent.putExtra("android.intent.extra.SUBJECT", "Enter Subject Here");
startActivity(Intent.createChooser(intent, "Select an email client")); 

Please check : https://developer.android.com/guide/components/intents-common#ComposeEmail

 String[] sendTo = {}; // people who will receive the email
    String subject = "implicit intent | sending email";
    String message = "Hi, this is just a test to check implicit intent.";
    Intent email = new Intent(Intent.ACTION_SENDTO);
    email.setData(Uri.parse("mailto:")); // only email apps should handle this
    email.putExtra(Intent.EXTRA_EMAIL, sendTo);
    email.putExtra(Intent.EXTRA_SUBJECT, subject);// email subject / title
    email.putExtra(Intent.EXTRA_TEXT, message);//message that you want to send

    // Create intent to show the chooser dialog
    Intent chooser = Intent.createChooser(email, "Choose an Email client :");
    // Verify the original intent will resolve to at least one activity
    if (chooser.resolveActivity(getPackageManager()) != null) {
        startActivity(chooser);
    }

This is an absolutely simple and 100% working approach. Thanks to the Open source developer, cketti for sharing this concise and neat solution.

String mailto = "mailto:bob@example.org" +
    "?cc=" + "alice@example.com" +
    "&subject=" + Uri.encode(subject) +
    "&body=" + Uri.encode(bodyText);

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(mailto));

try {
  startActivity(emailIntent);
} catch (ActivityNotFoundException e) {
  //TODO: Handle case where no email app is available
}

And this is the link to his/her gist.

Here's a code snippet that launches ONLY email apps.

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:example@example.com"));
intent.putExtra(Intent.EXTRA_SUBJECT, "This is the subject"));
intent.putExtra(Intent.EXTRA_TEXT, "Hi, how're you doing?"));

if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
    startActivity(intent);
}

I hope this helps.

Following three lines of code is sufficient to finish your task, nothing EXTRAS needed. Hope it helps.

Intent intent = new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:destination_gmail@gmail.com"));
startActivity(Intent.createChooser(intent, "Send email using.."));
Related