Android 选择电子邮件意图
我想从联系人列表中选择一封电子邮件。 选择一个联系人还不够好,因为一个联系人可能有多个电子邮件地址。
使用 API 演示,我成功地选择了联系人、电话号码,甚至地址。示例:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
// OR
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
// OR
intent.setType(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
但是,当尝试选择电子邮件时,
intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
我收到“活动未找到”异常。
知道如何从所有联系人的电子邮件中选择一封电子邮件吗?
谢谢。 阿利克.
更新(2011/05/02): 找到了另一种从联系人中挑选内容的方法,但电子邮件选择器仍然没有注册到意图。
工作:
new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI);
不工作:
new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Email.CONTENT_URI);
I'd like to pick an email from the contacts list.
Picking a contact is not good enough, because a contact can have several emails.
Using the API demo, I managed to pick a contact, phone number and even an address. Example:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
// OR
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
// OR
intent.setType(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE);
BUT, when trying to pick an email
intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
I get activity not found exception.
Any idea on how to pick an email from the all the contacts' emails?
Thanks.
Alik.
Update (2011/05/02):
Found another way to pick things from the contacts but still the email picker is not registered to the intent.
Working:
new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.Phone.CONTENT_URI);
new Intent(Intent.ACTION_PICK,ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_URI);
NOT working:
new Intent(Intent.ACTION_PICK, ContactsContract.CommonDataKinds.Email.CONTENT_URI);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我没有专门尝试使用选择器,但我们循环遍历联系人缓存并查找 MIME 类型为
Email.CONTENT_ITEM_TYPE
的所有联系人详细信息。然后我们构建一个对话框,让用户选择他们想要使用的电子邮件地址,并将该电子邮件地址传递给用户的电子邮件应用程序,例如
I haven't specifically tried to use a picker, but we loop through our cache of the contacts and find all the contact details with a MIME type of
Email.CONTENT_ITEM_TYPE
.Then we build a dialog to the let user pick which e-mail address they want to use, and we pass that e-mail address to the user's e-mail app, e.g.
您必须使用以下常量(不是 CONTENT_ITEM_TYPE):
you have to use the following constant (not CONTENT_ITEM_TYPE):
完美工作:
Perfectly working:
下面是一段示例代码,用于向用户显示联系人列表中的所有电子邮件地址并允许他们选择一个电子邮件地址(然后将其放入 ID 为 R 的
EditText
中)。 id.youredittextid)。注意:这是一种相当低效的方法,如果您有很多联系人,则会导致相当大的延迟。但所有必要的代码都在这里;根据您的需要进行定制...
Here's a sample bit of code to display all email addresses in the contact list to the user and allow them to select a single one (which is then put into an
EditText
with the id of R.id.youredittextid).Note: This is a rather inefficient way to do this, and will cause quite a delay if you have lots of contacts. But all the necessary code is here; customize as you see fit...
一个旧线程但是......这个信息可能对某人有用。
当您使用
Intent.ACTION_PICK
启动 Intent 时,您将尝试调用“联系人选择器”活动,该活动通常由联系人/电话簿应用程序提供。最新版本的普通 (Google) 通讯录应用 (Android 4.4.4) 的意图过滤器中确实有用于 mimetype 的
Email.CONTENT_ITEM_TYPE
,因此它应该响应此类意图,就像您所做的那样。我不确定,但旧版本(ICS、JB)的联系人选择器似乎在其意图过滤器中没有此功能。简而言之,此意图应该适用于安装了普通联系人的 KK,而不适用于较旧的 Android 版本。
An old thread but... this information could prove useful to someone.
When you start an Intent with
Intent.ACTION_PICK
you are trying to invoke the "Contact Picker" activity, which is usually supplied by Contacts / Phonebook application.Latest version of vanilla (Google) Contacts app (Android 4.4.4) does have
Email.CONTENT_ITEM_TYPE
for mimetype in its intent filter, so it should respond to such intent, just as you made it. I am not sure but it seems that Contact Picker for older versions (ICS, JB) did not have this in its intent filters.In short, this intent should work on KK with vanilla Contacts installed, and should not work on older Android versions.