14

Is it possible to open an emailclient such as gmail when I click a button in my app?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Hannelore
  • 763
  • 5
  • 11
  • 23
  • 1
    possible 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 Answers5

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
  • 12,492
  • 9
  • 66
  • 110
Robby Pond
  • 73,164
  • 16
  • 126
  • 119
  • 1
    does work mate. this is the way i did it Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts( "mailto", EMAIL_ADDRESS, null)); – Jono 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"));
Jono
  • 17,341
  • 48
  • 135
  • 217
  • 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,901
  • 2
  • 28
  • 32
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
  • 1,083
  • 11
  • 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
  • 459
  • 4
  • 7