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:
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?