0

I read this question to know how to send email in Android using ACTION_SEND: Sending email from android app

But problem is: I want to send email directly using Gmail, i don't want to show the action-list and choose Gmail again.

Can I do it?

Community
  • 1
  • 1
anticafe
  • 6,816
  • 9
  • 43
  • 74

2 Answers2

2

How to open Gmail Compose when a button is clicked in Android App? the second answer of beekeeper. Also duplicate of how to direct open Gmail mail composer in android? which has the same answer.

Community
  • 1
  • 1
Mojo Risin
  • 8,136
  • 5
  • 45
  • 58
0

Try this:

    final Intent intent = new Intent (android.content.Intent.ACTION_SEND);
    intent.setType ("text/plain");
    List<ResolveInfo> resInfo = getPackageManager ().queryIntentActivities (intent, 0);

    if (!resInfo.isEmpty ()) {
        for (ResolveInfo info : resInfo) {
            if (info.activityInfo.packageName.toLowerCase ().contains ("android.gm") || info.activityInfo.name.toLowerCase ().contains ("android.gm")) {


                intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
                intent.putExtra(android.content.Intent.EXTRA_SUBJECT, TextKonnex);
                intent.putExtra(android.content.Intent.EXTRA_TEXT, message);
                intent.setPackage (info.activityInfo.packageName);

                try {
                    startActivity (android.content.Intent.createChooser (intent,"Sending..."));
                    Toast.makeText(Main4Activity.this, "Sending an email to your friend! ", Toast.LENGTH_LONG).show();
                } catch (ActivityNotFoundException e) {


                    Toast.makeText(Main4Activity.this, "Error! Try whith other email address! ", Toast.LENGTH_LONG).show();
                }


            }
        }