Skip to content

Instantly share code, notes, and snippets.

@DhimanDasgupta
Created January 8, 2016 11:54
Show Gist options
  • Save DhimanDasgupta/651b36e8727f54a84530 to your computer and use it in GitHub Desktop.
Save DhimanDasgupta/651b36e8727f54a84530 to your computer and use it in GitHub Desktop.
public class EmailIntent {
public static void sendEmail(final Context context, final String mailTo, final String ccTo, final String subject, final String body) {
final WeakReference<Context> reference = new WeakReference<>(context);
String mailto = "mailto:" + mailTo +
"?cc=" + ccTo +
"&subject=" + Uri.encode(subject) +
"&body=" + Uri.encode(body);
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse(mailto));
try {
if (reference != null && reference.get() != null) {
startActivity(emailIntent);
}
} catch (ActivityNotFoundException e) {
//TODO: Handle case where no email app is available
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment