0

From my application I allow the user to send a message by email.

I use a code like that

Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:"));
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{Settings.getLastEmail()});
i.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.settings_DeviceID));
startActivity(i);

taken from how can I send emails from my android application.

At this point a gmail window appears and the user can enter the address in the "to" recipient.

I would like to retrieve the entered address so that I can show it as default "to" recipient the next time the user sends an email.

Is there a way to retrieve the entered address from gmail called with startActivity?

Klaus78
  • 11,648
  • 5
  • 32
  • 28
  • Even if it was possible to retrieve the email address from gmail (which I doubt is possible) you cannot be certain which email app the user has set as default. The user might not even have Gmail installed. – Barns Nov 28 '18 at 16:29

1 Answers1

1

This really isn't possible.

The "To" field in the Gmail application is not accessible to your project, and Gmail doesn't send any information back to your application when the user leaves it (Intents are one way).

Additionally, even if you were able to specifically interact with the Gmail application in this way, what if the user doesn't have the Gmail client installed? They may be using the native Email client, or Outlook, or any number of other possibilities.

You'd be better off using:

i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});

to send the recipients address to the email program from your software, storing the value entered by the user, and sending it by default next time.

keag
  • 299
  • 2
  • 15