Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
234 views
in Technique[技术] by (71.8m points)

android - Intent URI to launch Gmail App

Is there any URI which can point to the GMAIL App in android and help me launch it?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This works to intent just the gmail app.

final Intent intent = new Intent(Intent.ACTION_VIEW)
    .setType("plain/text")
    .setData(Uri.parse("[email protected]"))
    .setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail")
    .putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"})
    .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[] { "[email protected]" });

for single emails:

intent.setData(Uri.parse("[email protected]"));

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

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...