0

I'm trying to send an HTML text from my app by email. So I have this code:

StringBuilder sb = new StringBuilder();
// Lots of HTML building code...

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(Intent.EXTRA_SUBJECT, trip_to_manipulate.getTrip_name());
i.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(sb.toString()));
i.setType("message/rfc822");// to filter and display only email apps
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(getActivity(), "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}

But when I run this code I have whole bunch of apps showing up in the chooser:

enter image description here

I tried to start activity without createChoser, I tried to change type to text/html, I tried to use ACTION_SENDTO instead of ACTION_SEND, I tried them separately, I tried them combined, but I still got all these apps. Sometimes even more. And when they were combined the app crashed.

So is there a way to limit this list to email clients only?

Igal
  • 5,833
  • 20
  • 74
  • 132
  • There are several ways to do it, also this is a possible duplicate of http://stackoverflow.com/q/9730243/824914 – David Olsson Aug 07 '14 at 08:46
  • Looked through many answers here on SO, never saw this one. Thanks! I'll give it a try... – Igal Aug 07 '14 at 09:02

0 Answers0