Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

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

how to direct open Gmail mail composer in android?

I am using the following code. Problem it that when I run this code on device. It open a Dailogbox that hase 3 options for sending a mail. "POP , email , gmail" etc. By clicking the gamil the composer appear. I just want to show Gamil mail composer directly. Instead of showing a dailog box for choosing the options. Please help me.

Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/html");

String subject = "My Subject";

emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);

emailIntent.setType("text/html");

String title = "<p align='center'>" + storyTitle + "<br/>" + storyPubDate + "</p>";

String data = "<p> Sent From ABC APP Sent from my Android </p>";

            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(title + data));
startActivity(Intent.createChooser(emailIntent, "Email:"));
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Try this one, Perfect

public void shareToGMail(String[] email, String subject, String content) {
    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, email);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
    emailIntent.setType("text/plain");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, content);
    final PackageManager pm = activity.getPackageManager();
    final List<ResolveInfo> matches = pm.queryIntentActivities(emailIntent, 0);
    ResolveInfo best = null;
    for(final ResolveInfo info : matches)
        if (info.activityInfo.packageName.endsWith(".gm") || info.activityInfo.name.toLowerCase().contains("gmail"))
            best = info;
    if (best != null)
        emailIntent.setClassName(best.activityInfo.packageName, best.activityInfo.name);
    activity.startActivity(emailIntent);
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...