在 Android 上使用 ContactsContract api 获取联系人的邮政地址
我正在使用 ContactsContract api 意图来显示活动中的所有联系人。此意图返回联系人的 ID。我需要获取该联系人的邮政地址。
这是我用来显示联系人的代码:
意图intent = new Intent(Intent.ACTION_PICK); intent.setType(ContactsContract.Contacts.CONTENT_TYPE); startActivityForResult(意图,PICK_CONTACT);
我在 onActivityResult
函数中获取结果。
请帮忙,我该怎么做。
I am using ContactsContract api intent for showing all contacts from an activity. This intent returns an id of the contact. I need to get the postal address of this contact.
Here is the code which i am using for showing contacts:
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
I am getting the result in the onActivityResult
function.
Please help, how do i do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 onActivityResult 中,首先获取联系人 ID 并查询 ContactsContract.Data 中的相关数据:
in your onActivityResult, first get the contact ID and query the ContactsContract.Data for the relevant data:
也可以通过这种方式完成(代码较少)以
这种方式发送 Intent:
intent.setType(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
在onActivityResult方法中
Can be done this way too (little lesser code)
Send the Intent this way:
intent.setType(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
In the onActivityResult method
Kiran 的答案可能适用于 Android 2.0 及以上版本,但是当您希望它与 Android 1.6 及以下版本兼容时,您需要稍微调整一下代码:
在 onActivtyResult 方法中:
其中
PICK_CONTACT
是 < code>int 你自己选择的。 (正确的?)Kiran's answer probably works fine for Android 2.0 and above, but when you want it to be compatible for Android 1.6 and below you need to adapt the code a bit:
And in onActivtyResult method:
Where
PICK_CONTACT
is aint
of your own choice. (Right?)这将返回联系人邮政地址中的所有地址。
This will return all the addresses from the contact Postal Address.