From my app, I need to invoke an email client to send an email with attachment. I do not have the destination email address - that's something the user would be entering themselves. I used to have this code:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setDataAndType(Uri.parse("mailto:"), "text/plain");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_EMAIL, "");
intent.putExtra(Intent.EXTRA_SUBJECT, emailSubject);
intent.putExtra(Intent.EXTRA_TEXT, emailBody);
intent.putExtra(Intent.EXTRA_STREAM, attachmentUri);
try {
context.get().startActivity(intent);
} catch (ActivityNotFoundException ex) {
...
}
This worked perfectly fine up until Android 11. With Android 11, I get ActivityNotFoundException
. Now, if I remove the "data" element and replace call to setDataAndType
to simply setType("text/plain")
, then I get the activity selection popup to choose from, however it contains all activities and applications that support SEND action. How do I get to filter this list to email clients only?