Is there any URI which can point to the GMAIL App in android and help me launch it?
19 Answers
This works to intent just the gmail app.
final Intent intent = new Intent(Intent.ACTION_VIEW)
.setType("plain/text")
.setData(Uri.parse("test@gmail.com"))
.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail")
.putExtra(Intent.EXTRA_EMAIL, new String[]{"test@gmail.com"})
.putExtra(Intent.EXTRA_SUBJECT, "test")
.putExtra(Intent.EXTRA_TEXT, "hello. this is a message sent from my demo app :-)");
startActivity(intent);
use for plenty of emails:
intent.putExtra(Intent.EXTRA_EMAIL, new String[] { "test@gmail.com" });
for single emails:
intent.setData(Uri.parse("test@gmail.com"));
You may add extra putExtra(Intent.EXTRA..)
and change the setType
for your purpose. :P
Update (1/22/14): It is important to note that if you are going to use this code, you check to make sure that the user has the package "com.google.android.gm" installed on their device. In any language, make sure to check for null on specific Strings and initializations.
Please see Launch an application from another application on Android

- 54,294
- 25
- 151
- 185
-
1works nicely! also sendIntent.setData(Uri.parse("abc@gmail.com")); seems to be needless. – Oleksii Malovanyi Dec 26 '11 at 16:50
-
Does anyone know why it has to be new String[] { "abc@gmail.com" } instead of just "abc@gmail.com" for the 2nd parameter? – fIwJlxSzApHEZIl Jul 07 '12 at 06:03
-
It is a String array, it allows for multiple emails to be added. – Jared Burrows Jul 07 '12 at 06:20
-
3There are downvotes because setting the package manually to "com.google.android.gm" is undocumented, and could potentially break if the package name ever changes or is not installed. – LocalPCGuy Jan 22 '14 at 19:00
-
@LocalPCGuy Are you new to Android or just Java? You never copy and paste code from here. You need to modify it for 'null' checks. Make sure that package exists before you intent to that specified activity. – Jared Burrows Jan 22 '14 at 19:53
-
@JaredBurrows Both (but not programming in general), but I was leaving the comment because of the first comment you made, why it is getting minus 1 (I read that as downvotes). I don't copy/paste code from anywhere without understanding it first personally, but you and I know that is the exception and if checking for null package is a requirement it should state that in the message (which I see now it does, great!) – LocalPCGuy Jan 22 '14 at 20:07
-
This part is not needed: sendIntent.setData(Uri.parse("test@gmail.com")); Over all working fine and save me a lot of time.. :) Thank you! – mboy Sep 10 '14 at 09:51
-
@LocalPCGuy Is there a way of sending the email without specifying this line? - intent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail"); I'm getting a security error stating that the activity was not found. – iOSAndroidWindowsMobileAppsDev Jan 24 '17 at 05:58
-
Not really sure @Anon - I've not been working on Android since about the time this was originally posted. Maybe JaredBurrows can help. – LocalPCGuy Jan 24 '17 at 14:28
-
This used to work. I am getting Security exception since quite some time now. Perhaps earlier the 'ComposeActivityGmail' was exported & now it is not. – Swas_99 Aug 21 '17 at 09:12
-
@Swas_99 Which API level? – Jared Burrows Aug 21 '17 at 16:22
-
@Jared : API level 19 – Swas_99 Aug 22 '17 at 06:10
-
Odd, I would expect an exception on a higher level device. Maybe there is a better way, just using an intent resolver for all email apps instead of this one directly. – Jared Burrows Aug 22 '17 at 19:25
-
8java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=test@gmail.com cmp=com – Irfan Raza Aug 24 '17 at 18:54
-
1@IrfanRaza did you find solution for java.lang.SecurityException: Permission Denial: starting Intent { act=android.intent.action.VIEW dat=test@gmail.com cmp=com ? If yes the please tell me the solution. – Amit Jayaswal Apr 10 '18 at 05:04
-
Use this solution: https://stackoverflow.com/a/21700622/7213349 – Michał Jabłoński Sep 09 '20 at 09:41
-
Working solution: Instead of `setClassName`, use `setPackage("com.google.android.gm")` – Lorenzo Sep 16 '20 at 19:39
I'm using this in my apps:
Intent mailClient = new Intent(Intent.ACTION_VIEW);
mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivity");
startActivity(mailClient);

- 858
- 8
- 10
-
1
-
36That is undocumented, unsupported, and may well break in the future. – CommonsWare Sep 18 '11 at 12:28
-
5Targeting API 17 I'm getting a `android.content.ActivityNotFoundException: Unable to find explicit activity class {com.google.android.gm/com.google.android.gm.ConversationListActivity}; have you declared this activity in your AndroidManifest.xml?` Any ideas? – Garret Wilson Nov 16 '12 at 21:59
-
Getting the launch intent for the package, as indicated [below](http://stackoverflow.com/a/7249579/421049), works for me. – Garret Wilson Nov 16 '12 at 22:13
-
1Calling `setPackage("com.google.android.gm")`, which is available since ICS, is undocumented as well, but is very unlikely to break as the package name will probably not change. – caw May 30 '13 at 00:41
-
-
@CommonsWare Currently my implementation is showing the Google drive also. Is there any updated methods by which i can launch just the gmail app – Ajith M A Feb 11 '14 at 09:45
-
@garret use mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail"); – Ajay Pandya Mar 27 '15 at 12:48
-
3Now its not working....can use: Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.gm"); startActivity(intent); – Shivang Feb 18 '16 at 08:57
-
7The 2nd parameter (`className`) is `"com.google.android.gm.ConversationListActivityGmail"` for the time of writing (Gmail v6.7, Marshmallow). – Quoting Eddie Aug 21 '16 at 14:44
Using package name is not recommended as its an undocumented method. In case if the package name changes some day the code will fail.
Try this code instead
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto", "abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "This is my subject text");
context.startActivity(Intent.createChooser(emailIntent, null));
Ref: http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO\

- 3,838
- 3
- 32
- 55
-
1Use try catch block to prevent crash if package name changes in future. But setting package name gives better UX, so for gmail we should go with package – CopsOnRoad Feb 10 '18 at 07:07
Use this:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.gm");
startActivity(intent);
This could be device and API level dependent. Use with care.

- 237,138
- 77
- 654
- 440

- 2,401
- 24
- 29
-
Can you tell me how can i pass emails to gmail search box via above intent? – Vatsal Dholakiya May 10 '21 at 12:40
-
Simple and 100 % working
Intent intent = new Intent (Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"anyMail@gmail.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "Any subject if you want");
intent.setPackage("com.google.android.gm");
if (intent.resolveActivity(getPackageManager())!=null)
startActivity(intent);
else
Toast.makeText(this,"Gmail App is not installed",Toast.LENGTH_SHORT).show();

- 237,138
- 77
- 654
- 440
Try this
i have tried to many solutions but finally i got a correct way that works fine for me
try {
Intent intent = new Intent (Intent.ACTION_VIEW , Uri.parse("mailto:" + "your_emailid@gmail.com"));
intent.putExtra(Intent.EXTRA_SUBJECT, "your_subject");
intent.putExtra(Intent.EXTRA_TEXT, "your_text");
startActivity(intent);
} catch(Exception e) {
Toast.makeText(Share.this, "Sorry...You don't have any mail app", Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
Note
- This will open your installed mail application(Email,Gmail) to send mail in which you can select one among them.
- Don't use direct package name like("com.google.android.gm") because in future if they change package name your app will face problems.
-
1It worked, Thanks. Didn't had to stumble on other options, found this quickly. – Diljeet Oct 23 '17 at 10:10
Later the requirements changed to starting an "Email app", so the below code basically starts an email app and the user has to choose among the choices shown up.
So, I had to use
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_SUBJECT, "Emailing link");
intent.putExtra(Intent.EXTRA_TEXT, "Link is \n" +
"This is the body of hte message");
startActivity(Intent.createChooser(intent, ""));

- 8,861
- 2
- 30
- 34

- 9,895
- 15
- 59
- 87
-
If you see clearly what droid_fan has answered then it launches email app only on particular devices but my answer launches the email app no matter what the platform is. – Sana Sep 18 '11 at 01:29
-
+1 for the alternative. Having looked again perhaps Richard Lalancette's answer provides a more generic solution for launching packages with unknown launch intent details. – Moog Sep 18 '11 at 02:03
-
This will also show things like PayPal in the intent picker. May not be what you want users to see. – zyamys Sep 09 '17 at 16:59
This trick work for ALL version (API 3+), as well as text/plain or text/html (by sonida) :
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/html");
// 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;
break;
}
}
if (best != null) {
intent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
}
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "YOUR SUBJECT");
intent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml("YOUR EXTRAS"));
startActivity(intent);
It works.
Intent intent = new Intent(Intent.ACTION_SEND);
String[] strTo = { getString(R.string.mailto) };
intent.putExtra(Intent.EXTRA_EMAIL, strTo);
intent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.mail_subject));
intent.putExtra(Intent.EXTRA_TEXT, getString(R.string.mail_body));
Uri attachments = Uri.parse(image_path);
intent.putExtra(Intent.EXTRA_STREAM, attachments);
intent.setType("message/rfc822");
intent.setPackage("com.google.android.gm");
startActivity(intent);

- 69
- 1
- 2
The best way to do it, is by using the generic way/method:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("plain/text");
intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject goes here");
intent.putExtra(Intent.EXTRA_TEXT, "Your Message goes here");
startActivity(Intent.createChooser(intent, ""));
This will give the users a choice where they can pick GMail (if installed) or any other email supporting app they have.

- 520
- 6
- 15
Please check the following code it'll open default mail composer automatically.
try {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_EMAIL);
context.startActivity(intent);
} catch (android.content.ActivityNotFoundException anfe) {
handleException();
}

- 29
- 2
-
This worked for me. I was just interested in opening the email client not composing a new email. – speedynomads Feb 17 '21 at 16:25
startActivity(new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:"+mailId)));

- 2,394
- 1
- 19
- 15
Yes its working code perfectly.....
Intent intent = new Intent(Intent.ACTION_SEND);
String[] strTo = { "test@g.com" };
intent.putExtra(Intent.EXTRA_EMAIL, strTo);
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "Body");
intent.setType("message/rfc822");
intent.setPackage("com.google.android.gm");
startActivity(intent);

- 171
- 2
- 12
-
it's 2023 and Android changed `getPackageManager().queryIntentActivities()` to no longer return the GMail package. But priyanka's code still works because the GMail package still has the literal package name `com.google.android.gm`. – Phlip Feb 15 '23 at 22:50
Working as for me is just simple like this:
Intent(Intent.ACTION_SEND).apply{
setPackage("com.google.android.gm")
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, "Go, go share text!")
}.also{readyIntent->
startActivity(readyIntent)
}

- 2,351
- 24
- 35
This snippet will open a chooser which is supposed to point to Gmail inbox.
val intent = Intent(Intent.ACTION_MAIN)
intent.addCategory(Intent.CATEGORY_APP_EMAIL)
try {
startActivity(Intent.createChooser(intent, getString(R.string.open_email_app)))
} catch (e: ActivityNotFoundException) {
showErrorDialog(R.string.error_activity_is_not_found)
}

- 622
- 8
- 15
Neither was working for me, as the subject and message were always empty, until I found the official solution here.
fun composeEmail(addresses: Array<String>, subject: String, attachment: Uri) {
val intent = Intent(Intent.ACTION_SEND).apply {
type = "*/*"
putExtra(Intent.EXTRA_EMAIL, addresses)
putExtra(Intent.EXTRA_SUBJECT, subject)
putExtra(Intent.EXTRA_STREAM, attachment)
}
if (intent.resolveActivity(packageManager) != null) {
startActivity(intent)
}
}

- 4,005
- 2
- 18
- 31
This answer is old,but still appears in the Google Search at first position.
Hence,from the android documentation,the better way to do this now is :
public void composeEmail(String[] addresses, String subject, Uri attachment) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("*/*");
intent.putExtra(Intent.EXTRA_EMAIL, addresses);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(Intent.EXTRA_STREAM, attachment);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
}
}
More information can be found out at here

- 86
- 3
- 12
final String package = "com.google.android.gm";
// return true if gmail is installed
boolean isGmailInstalled = isAppInstalled(MainActivity.this, package);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_EMAIL, new String[] {"mail@gamil.com"});
if (isGmailInstalled) {
intent.setType("text/html");
intent.setPackage(package);
startActivity(intent);
} else { // allow user to choose a different app to send email with
intent.setType("message/rfc822");
startActivity(Intent.createChooser(intent, "choose an email client"));
}
// Method to check if app is installed
private boolean isAppInstalled(Context context, String packageName) {
try {
context.getPackageManager().getApplicationInfo(packageName, 0);
return true;
} catch (PackageManager.NameNotFoundException e) {
return false;
}
}

- 62
- 6
Intent URI to launch Gmail App
Intent mailClient = new Intent(Intent.ACTION_VIEW);
mailClient.setClassName("com.google.android.gm", "com.google.android.gm.ConversationListActivityGmail");
startActivity(mailClient);

- 4,596
- 8
- 33
- 44

- 1
- 1