通过Gmail发送电子邮件 [英] Send email via gmail

查看:755
本文介绍了通过Gmail发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有c中的火灾意图$ C $发送电子邮件

I have a code the fires intent for sending email

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL,
                new String[] { to });
i.putExtra(Intent.EXTRA_SUBJECT, subject);
i.putExtra(Intent.EXTRA_TEXT, msg);
try {
    startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(Start.this,
                    "There are no email clients installed.",
                    Toast.LENGTH_SHORT).show();
}

但是,当这个意图解雇我看到喜欢的短信应用,Gmail应用程序,Facebook应用程序等就行了许多项目。

But when this intent is fired I see many item in the list like sms app , gmail app, facebook app and so on.

如何过滤这一点,只启用Gmail应用程序(或者只是电子邮件应用程序)?

How can I filter this and enable only gmail app (or maybe just email apps)?

推荐答案

使用 android.content.Intent.ACTION_SENDTO 新意图(意图。 ACTION_SENDTO); ),以获取电子邮件客户端只有列表中,没有Facebook或其他应用程序。就在电子邮件客户端。

Use android.content.Intent.ACTION_SENDTO (new Intent(Intent.ACTION_SENDTO);) to get only the list of e-mail clients, with no facebook or other apps. Just the email clients.

我不建议你直接到电子邮件应用程序。让用户选择他喜欢的电子邮件应用程序。 不要限制他。

I wouldn't suggest you get directly to the email app. Let the user choose his favorite email app. Don't constrain him.

如果您使用ACTION_SENDTO,putExtra不起作用添加主题和文本的意图。使用URI来添加主题和正文文本。

If you use ACTION_SENDTO, putExtra does not work to add subject and text to the intent. Use Uri to add the subject and body text.

Intent send = new Intent(Intent.ACTION_SENDTO);
String uriText = "mailto:" + Uri.encode("email@gmail.com") + 
          "?subject=" + Uri.encode("the subject") + 
          "&body=" + Uri.encode("the body of the message");
Uri uri = Uri.parse(uriText);

send.setData(uri);
startActivity(Intent.createChooser(send, "Send mail..."));

这篇关于通过Gmail发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆