如何在 android 中直接打开 Gmail 邮件编辑器?

how to direct open Gmail mail composer in android?(如何在 android 中直接打开 Gmail 邮件编辑器?)

本文介绍了如何在 android 中直接打开 Gmail 邮件编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码.当我在设备上运行此代码时会出现问题.它会打开一个 Dailogbox,其中包含 3 个用于发送邮件的选项.POP、电子邮件、gmail"等.通过单击 gamil,作曲家出现.我只想直接显示 Gamil 邮件编写器. 而不是显示用于选择选项的对话框.请帮我.

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:"));

推荐答案

试试这个,完美

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);
}

这篇关于如何在 android 中直接打开 Gmail 邮件编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 android 中直接打开 Gmail 邮件编辑器?

基础教程推荐