Created
January 8, 2016 11:54
-
-
Save DhimanDasgupta/651b36e8727f54a84530 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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