0

I am using this code to use email application from my app.

String mailText = "Full Name:" + fname.getText().toString();
String subject = "Support";
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[] { "support@roncocala.com" });

email.putExtra(Intent.EXTRA_SUBJECT, subject);
email.setType("plain/text");

email.putExtra(Intent.EXTRA_TEXT, mailText);

startActivity(Intent.createChooser(email, "Choose an Email client :"));

But it shows extra applications like SKype and ES File Lan . Is there a way to limit these application to mail applications like gmail,yahoo,hotmail. Please help.Thanks.

Batuhan Coşkun
  • 2,961
  • 2
  • 31
  • 48
  • possible duplicate of [Android - How to filter specific apps for ACTION\_SEND intent](http://stackoverflow.com/questions/9730243/android-how-to-filter-specific-apps-for-action-send-intent) – Pankaj Kumar Jan 06 '14 at 08:54

3 Answers3

1

To get only email client you need to use android.content.Intent.ACTION_SENDTO :

new Intent(Intent.ACTION_SENDTO); // return only the list of e-mail clients

you need to have configured an email account on those email client app or you'll have the error : "No application can perform this action".

Andros
  • 4,069
  • 1
  • 22
  • 30
0

ACTION_SENDTO only seems to be working for newer OS (at least API LEVEL 17+).

Unfortunately, this is the "best" current way of limiting the application list if you want to support older Android OS.

emailIntent.setType("message/rfc822");

Ernir Erlingsson
  • 2,150
  • 1
  • 19
  • 17
0

None of the above solutions worked for me. After a lot of searching and testing, I finally found a good solution. Thanks to the Open source developer, cketti for sharing his/her 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.

user10496632
  • 463
  • 4
  • 13