0

I'm sending mail from gmail default email client composer. Now I have following concerns regarding sending mail:

  1. In Android older versions, when I sent mail from gmail composer then by device back button I'm able to come back to my app, however in Android Marshmallow it goes to gmail instead to come back to my app (Not sure about Lollipop)
  2. In any of Android version I don't have feature to get callback response from gmail to check whether my mail has been sent or not.

I'm using following code to sending mail

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");

final PackageManager pm = getPackageManager();
final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
ResolveInfo best = null;

for (final ResolveInfo info : matches)
    if (info.activityInfo.packageName.endsWith(".gm") ||
           info.activityInfo.name.toLowerCase().contains("gmail")) best = info;
              if (best != null)
                  intent.setClassName(best.activityInfo.packageName, best.activityInfo.name);

intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailId});
startActivity(intent)

I went through such links :

Send Email Intent

Sending email on android via default email application

(And many more)

Please Help!

Community
  • 1
  • 1
Harish Godara
  • 2,388
  • 1
  • 14
  • 28

1 Answers1

0

I don't have a device to test .but this may help you . let me know if it works

   startActivityForResult(intent,RESULT_OK);
mehd azizi
  • 594
  • 1
  • 5
  • 16
  • 1
    This will not work as **the actual sending of an email is asynchronous by design**, so the activity will likely return before the email is actually sent. Here is another link for the same : http://stackoverflow.com/questions/3778048/how-can-we-use-startactivityforresult-for-email-intent – Harish Godara Jun 30 '16 at 07:00