按电话号码搜索联系人
在我的应用程序中,用户输入一个电话号码,我想查找该电话号码的联系人姓名?
我通常这样搜索联系人:
Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
但我这样做是为了访问所有联系人...在这个应用程序中,我只想获取给定电话号码的联系人姓名...如何限制查询?
或者我是否必须遍历所有联系人并查看是否有给定的电话号码?但我相信这样会很慢......
In my app, user writes a phone number, and I want to find the contact name with that phone number?
I usually search the contacts like this:
Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null, null, null, null);
But I do this to access all contacts... In this app I only want to get the contact name of the given phone number... How can I restrict the query?
Or do I have to go trough all contacts and see if any has the given phone number? But I believe that this can be very slow this way...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果你想要完整的代码:
If you want the complete code:
您应该查看推荐的 ContactsContract.PhoneLookup 提供商
A表,表示查找电话号码的结果,例如呼叫者 ID。要执行查找,您必须将要查找的号码附加到 CONTENT_FILTER_URI。该查询经过高度优化。
You should have a look at the recommended ContactsContract.PhoneLookup provider
A table that represents the result of looking up a phone number, for example for caller ID. To perform a lookup you must append the number you want to find to CONTENT_FILTER_URI. This query is highly optimized.