Thanks to Pentium10’s suggestion of searching how Linkify works, I have found a great solution to this problem. Basically, you just create a “mailto:” link, and then call the appropriate Intent for that.:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
There are a few interesting aspects to this solution:
-
I’m using the ACTION_VIEW action because that’s more appropriate for a “mailto:” link. You could provide no particular action, but then you might get some unsatisfactory results (for example, it will ask you if you want to add the link to your contacts).
-
Since this is a “share” link, I am simply including no email address – even though this is a mailto link. It works.
-
There’s no chooser involved. The reason for this is to let the user take advantage of defaults; if they have set a default email program, then it’ll take them straight to that, bypassing the chooser altogether (which seems good in my mind, you may argue otherwise).
Of course there’s a lot of finesse I’m leaving out (such as properly encoding the subject/body), but you should be able to figure that out on your own.