发送电子邮件意图 [英] Send Email Intent
问题描述
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/html");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
以上代码打开一个对话框,显示以下应用程序:-蓝牙、Google Docs、Yahoo Mail、Gmail、Orkut、Skype 等
The above code opens a dialog showing following apps:- Bluetooth, Google Docs, Yahoo Mail, Gmail, Orkut, Skype etc.
实际上,我想过滤这些列表选项.我只想显示电子邮件相关的应用程序,例如Gmail,雅虎邮箱.怎么做?
Actually, I want to filter these list-options. I want to show only email related apps e.g. Gmail, Yahoo Mail. How to do it?
我在Android Market"应用程序上看到过这样的例子.
I've seen such example on 'Android Market' application.
- 打开安卓电子市场应用
- 打开开发者指定了他/她的电子邮件地址的任何应用程序.(如果你找不到这样的应用程序,只需打开我的应用程序:- market://details?id=com.becomputer06.vehicle.diary.free ,或通过车辆日记"搜索)
- 向下滚动到开发人员"
- 点击发送电子邮件"
该对话框仅显示电子邮件应用程序,例如Gmail、Yahoo Mail 等.它不显示蓝牙、Orkut 等.什么代码会产生这样的对话框?
The dialog shows only email Apps e.g. Gmail, Yahoo Mail etc. It does not show Bluetooth, Orkut etc. What code produces such dialog?
推荐答案
当你像下面一样改变你的 intent.setType 你会得到
when you will change your intent.setType like below you will get
intent.setType("text/plain");
使用 android.content.Intent.ACTION_SENDTO
仅获取电子邮件客户端列表,没有 Facebook 或其他应用程序.只是电子邮件客户端.例如:
Use android.content.Intent.ACTION_SENDTO
to get only the list of e-mail clients, with no facebook or other apps. Just the email clients.
Ex:
new Intent(Intent.ACTION_SENDTO);
我不建议您直接访问电子邮件应用.让用户选择他最喜欢的电子邮件应用程序.不要束缚他.
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.
我们可以使用 message/rfc822
而不是 "text/plain"
作为 MIME 类型.然而,这并不表示只提供电子邮件客户端"——它表示提供任何支持消息/rfc822 数据的东西".这很容易包括一些不是电子邮件客户端的应用程序.
We can use message/rfc822
instead of "text/plain"
as the MIME type. However, that is not indicating "only offer email clients" -- it indicates "offer anything that supports message/rfc822 data". That could readily include some application that are not email clients.
message/rfc822
支持 .mhtml、.mht、.mime
这篇关于发送电子邮件意图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!