Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void openGmail(String address, String subject, String text)
- {
- Intent intent = new Intent(android.content.Intent.ACTION_SEND);
- intent.setType("text/html");
- // Get a list of all activities that can handle intents of type ACTION_SEND
- List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);
- for (ResolveInfo info : resInfo) {
- String type = "gmail";
- // Check if the given activity is from the Gmail application
- if (info.activityInfo.packageName.toLowerCase().contains(type)
- || info.activityInfo.name.toLowerCase().contains(type)) {
- // 'Write'p the Email
- intent.putExtra(Intent.EXTRA_EMAIL, new String[] {address});
- intent.putExtra(Intent.EXTRA_SUBJECT, subject);
- intent.putExtra(Intent.EXTRA_TEXT, text);
- intent.setPackage(info.activityInfo.packageName);
- // The following will not start the chooser but GMail directly
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- startActivity(Intent.createChooser(intent, "Send mail"));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement