Beruflich Dokumente
Kultur Dokumente
Stack Overflow
log in
12
Is there any URI which can point to the GMAIL App in android and help me launch it?
share
Asked
Aug 12 '10 at 16:49
jball
18k 7 49 81
Edited
Aug 12 '10 at 16:53
8 Answers
15
Order By
Votes
share
Answered
Aug 28 '10 at 19:07
Excellent answer! I was looking for it since a long time. Sana Aug 29 '10 at 17:47
i searched for 4 hours and now i got my ans ,,, thanks a ton djk Mar 24 '11 at 12:26
12
That is undocumented, unsupported, and may well break in the future. CommonsWare Sep 18 '11 at 12:28
I think it's best to wrap that code in a try catch Marco Matarazzi Sep 4 '12 at 13:30
30
share
Answered
Sep 17 '11 at 16:20
Edited
Mar 10 '14 at 17:07
Why is there a minus 1? This code works... Jared Burrows Oct 2 '11 at 3:49
Does anyone know why it has to be new String[] { "abc@gmail.com" } instead of just "abc@gmail.com" for the 2nd
parameter? anon58192932 Jul 7 '12 at 6:03
It is a String array, it allows for multiple emails to be added. Jared Burrows Jul 7 '12 at 6:20
There 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
show 3 more comments
I tried so many things today, I was getting frustrated ahaha. I just wanted to launch the email
client... this is what solved it for me:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.gm");
startActivity(intent);
This could be device and API level dependent. Use with care.
share
Answered
Aug 30 '11 at 20:44
Edited
Apr 13 '14 at 14:19
share
Answered
Aug 12 '10 at 17:45
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
share
Answered
Jun 20 '11 at 19:47
Edited
Dec 31 '14 at 18:23
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 1: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. Merlin Sep 18 '11 at 2:03
add a comment
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("g
mail")) {
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);
share
Answered
Mar 12 '13 at 12:42
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
Ref: http://developer.android.com/reference/android/content/Intent.html#ACTION_SENDTO\
share
Answered
Feb 11 '14 at 11:29
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);
share
Answered
Jan 29 '15 at 1:56
Edited
Jan 29 '15 at 3:07
Your Answer
log in
or
Name
By posting your answer, you agree to the privacy policy and terms of service.
meta chat tour help blog privacy policy legal contact us full site
Download the Stack Exchange Android app
2016 Stack Exchange, Inc