Android & Wordpress Help center

Android: Share via installed email clients ONLY!

Came across this very easy and clean way of showing users ONLY email clients to choose from while sharing anything via email.

So here goes the code:-

* Displays a dialog to share via email
* @param mailTo
* @param mailSubject
* @param mailBody
* @param context
private void shareViaEmail(String mailTo, String mailSubject,
String mailBody, Context context) {
// To ensure that only email clients show up in the chooser menu, we are using mailto string
StringBuilder builder = new StringBuilder("mailto:" + Uri.encode(mailTo));
if (mailSubject != null) {
builder.append("?subject=" + Uri.encode(Uri.encode(mailSubject)));
if (mailBody != null) {
builder.append("&body=" + Uri.encode(Uri.encode(mailBody)));
String uri = builder.toString();
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));



Single Post Navigation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: