使用联系人选择器时从具有多个号码的用户中选择一个号码
我试图允许用户使用联系人选择器从联系人中选择电话号码。但是,现在我在网上看到的所有示例都显示了如何选择联系人,但我希望如果该联系人有多个电话号码,那么会弹出第二个屏幕,以便您可以指定要选择哪个电话号码(方式当您选择联系人时,该短信可让您执行此操作)。
我的问题是,您是否必须收集所有数字,然后要求用户选择一个数字,或者此功能是否已内置于 Android 中?我希望我只是忘记了一面旗帜或其他东西。
I'm trying to allow a user to select a phone number from a contact using the contact picker. However, right now all the examples I see online show how you can select a contact, but I am hoping to have a second screen then pop up if that contact has multiple phone numbers so you can specify which one you want to select (the way that text message lets you do so when you select a contact).
My question is, do you have to gather all of the numbers and then ask the user to select a number, or is this functionality already built into Android? I'm hoping I just forgot a flag or something.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我可以通过创建第二个对话框来做到这一点,该对话框显示与联系人关联的所有电话号码。
首先,在代码中的某个位置调用它:
然后在 onActivityResult() 中使用它来确定所选联系人是否有多个电话号码,如果有,则显示一个对话框:
我知道这是一个老问题,但我希望它有所帮助。
I was able to do this by creating a second dialog which shows all the phone numbers associated with a contact.
First, call this somewhere in your code:
Then in onActivityResult() use this to decide if the selected contact has multiple phone numbers, and display a dialog if so:
I know this is an old question but I hope it helps.
以防万一有人再次偶然发现这一点。
其他答案的另一个替代方案是库 https://github.com/codinguser/android_contact_picker
全面披露:我是这个库的作者
Just in case someone stumbles across this again.
Another alternative to the other answers is the library https://github.com/codinguser/android_contact_picker
Full Disclosure: I am the author of this library
Android 开发者参考上有简单的解释:
https://developer.android.com/training/contacts- provider/modify-data.html#InsertEdit
和简单的附加代码:
如果您需要活动结果,您必须通过以下方式监听活动上的 onActivityResult 事件
REQUEST_CODE_ADD_PHONE_CONTACT
变量。it is simple explained on android developers reference:
https://developer.android.com/training/contacts-provider/modify-data.html#InsertEdit
and simple append code:
if you needed activity result, you must listen to onActivityResult event on Activity by
REQUEST_CODE_ADD_PHONE_CONTACT
variable.或者,您可以首先在联系人选择器中显示与每个联系人关联的电话号码,然后以这种方式选择一个。以这种方式启动联系人选择器(注意与我的其他答案不同的 URI):
然后,在 onActivityResult() 中:
Alternatively, you can initially display the phone numbers associated with each contact in the Contact Picker and select one that way. Launch contact picker this way (note the different URI than my other answer):
Then, in onActivityResult():