Android 以编程方式打开电子邮件客户端

发布于 2024-10-31 18:16:17 字数 45 浏览 0 评论 0原文

当我单击应用程序中的按钮时,是否可以打开电子邮件客户端(例如 Gmail)?

Is it possible to open an emailclient such as gmail when I click a button in my app?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

榆西 2024-11-07 18:16:17

是的。您可以通过意图启动它。

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(i, "Send email"));

Yes. You can launch it via Intents.

Intent i = new Intent(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ emailAddress });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
i.putExtra(android.content.Intent.EXTRA_TEXT, text);
startActivity(Intent.createChooser(i, "Send email"));
尘曦 2024-11-07 18:16:17
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto", EMAIL_ADDRESS, null));

最新的做法

        i.putExtra(android.content.Intent.EXTRA_SUBJECT, SUBJECT);
        i.putExtra(android.content.Intent.EXTRA_TEXT, BODY);
        startActivity(Intent.createChooser(i, "Send email"));
Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
                    "mailto", EMAIL_ADDRESS, null));

up to date way of doing it

        i.putExtra(android.content.Intent.EXTRA_SUBJECT, SUBJECT);
        i.putExtra(android.content.Intent.EXTRA_TEXT, BODY);
        startActivity(Intent.createChooser(i, "Send email"));
带刺的爱情 2024-11-07 18:16:17

如果上面的代码不起作用,请尝试此操作。
已测试并工作

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("vnd.android.cursor.item/email"); 
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{Constants.FEEBBACK_EMAIL_ADDRESS});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
startActivity(Intent.createChooser(intent, "Send mail using..."));

If above code is not working then try this.
Tested and working

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setType("vnd.android.cursor.item/email"); 
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{Constants.FEEBBACK_EMAIL_ADDRESS});
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT");
startActivity(Intent.createChooser(intent, "Send mail using..."));
不甘平庸 2024-11-07 18:16:17

这对我来说效果很好

Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setType("text/plain");
                shareIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"[email protected]"} );
                shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support: Speech to text App");
                startActivity(Intent.createChooser(shareIntent, "Share "));

This Worked fine for me

Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.setType("text/plain");
                shareIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"[email protected]"} );
                shareIntent.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support: Speech to text App");
                startActivity(Intent.createChooser(shareIntent, "Share "));
勿挽旧人 2024-11-07 18:16:17

如果没有附件,您可以简单地使用以下代码:

Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:[email protected]")); 
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
startActivity(Intent.createChooser(emailIntent, "Send feedback"));

有关详细信息,我建议访问:
https://developer.android.com/guide/components/intents- common.html#电子邮件

You can simply use below code when for no attachment:

Intent i = new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("mailto:[email protected]")); 
i.putExtra(Intent.EXTRA_SUBJECT, "Feedback/Support");
startActivity(Intent.createChooser(emailIntent, "Send feedback"));

For details I recommend to visit:
https://developer.android.com/guide/components/intents-common.html#Email

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文