Is it possible to open an emailclient such as gmail when I click a button in my app?
Asked
Active
Viewed 1.1k times
14
-
1possible duplicate of [How to open Gmail Compose when a button is clicked in Android App?](http://stackoverflow.com/questions/3935009/how-to-open-gmail-compose-when-a-button-is-clicked-in-android-app) – Yoni Samlan Apr 08 '11 at 15:13
5 Answers
28
Yes. You can launch it via Intents.
Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(i, "Send email"));
vidstige
- 11,888
- 8
- 65
- 104
Robby Pond
- 72,024
- 16
- 123
- 118
-
1does work mate. this is the way i did it Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto", EMAIL_ADDRESS, null)); – Jonathan Jul 09 '15 at 09:06
6
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", EMAIL_ADDRESS, null));
up to date way of doing it
i.putExtra(android.content.Intent.EXTRA_SUBJECT, SUBJECT);
i.putExtra(android.content.Intent.EXTRA_TEXT, BODY);
startActivity(Intent.createChooser(i, "Send email"));
Jonathan
- 16,547
- 47
- 128
- 211
-
Fyi to anyone, I think the `Intent.createChooser(i, "Send email")` part is not necessary. It lets you customize the message. For the standard chooser/picker, you can simply call `startActivity(i)` – Aba Jun 11 '18 at 02:50
0
If above code is not working then try this. Tested and working
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("vnd.android.cursor.item/email");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{Constants.FEEBBACK_EMAIL_ADDRESS});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
startActivity(Intent.createChooser(intent, "Send mail using..."));
AkshayT
- 2,621
- 2
- 23
- 30
0
This Worked fine for me
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"mobiz@gmail.com"} );
shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support: Speech to text App");
startActivity(Intent.createChooser(shareIntent, "Share "));
Guri S
- 965
- 10
- 12
0
You can simply use below code when for no attachment:
Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:support@mailname.com"));
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
startActivity(Intent.createChooser(emailIntent, "Send feedback"));
For details I recommend to visit: https://developer.android.com/guide/components/intents-common.html#Email
Monir Zzaman
- 369
- 3
- 7