Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email body empty when select to send email by Gmail

I'm using this code:

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto",email, null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, text);
activity.startActivity(Intent.createChooser(emailIntent, "Send feedback to xyz"));

for 2 years. And until now everything worked fine. User can select message client and send feedback with prefilled data inside. It worked fine for all mail clients. Recently noticed that if I select gmail client - body of message remains empty, but on other mail clients body is filled with text.

Any ideas?

like image 365
Kostadin Avatar asked Jan 21 '20 08:01

Kostadin


1 Answers

Thanks for help

Made tests with lots of suggested answers. adding "text/plain" or "message/rfc822" made my app to stop offering mail clients.

Fount this answer that fixed my issue: https://stackoverflow.com/a/59365539/973233

Most interesting part for me is having 2 intents:

Intent selectorIntent = new Intent(Intent.ACTION_SENDTO);
selectorIntent.setData(Uri.parse("mailto:"));
final Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{email});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, text);
emailIntent.setSelector( selectorIntent );
activity.startActivity(Intent.createChooser(emailIntent, "Send feedback to XYZ"));

This solved problem.

like image 80
Kostadin Avatar answered Sep 27 '22 22:09

Kostadin