Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. private void openGmail(String address, String subject, String text)
  2. {
  3. Intent intent = new Intent(android.content.Intent.ACTION_SEND);
  4. intent.setType("text/html");
  5.  
  6. // Get a list of all activities that can handle intents of type ACTION_SEND
  7. List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(intent, 0);
  8. for (ResolveInfo info : resInfo) {
  9. String type = "gmail";
  10. // Check if the given activity is from the Gmail application
  11. if (info.activityInfo.packageName.toLowerCase().contains(type)
  12. || info.activityInfo.name.toLowerCase().contains(type)) {
  13. // 'Write'p the Email
  14. intent.putExtra(Intent.EXTRA_EMAIL, new String[] {address});
  15. intent.putExtra(Intent.EXTRA_SUBJECT, subject);
  16. intent.putExtra(Intent.EXTRA_TEXT, text);
  17. intent.setPackage(info.activityInfo.packageName);
  18. // The following will not start the chooser but GMail directly
  19. intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  20.  
  21.  
  22. startActivity(Intent.createChooser(intent, "Send mail"));
  23. }
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement