按电话号码检索联系人 [英] Search contact by phone number

查看:175
本文介绍了按电话号码检索联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,用户写的电话号码,我想找到与该电话号码的联系人姓名?

In my app, user writes a phone number, and I want to find the contact name with that phone number?

我通常寻找这样联系人:
光标CUR = getContentResolver()查询(ContactsContract.Contacts.CONTENT_URI,                 NULL,NULL,NULL,NULL);

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...

推荐答案

您应该看看推荐的<一个href="http://developer.android.com/intl/de/reference/android/provider/ContactsContract.PhoneLookup.html">ContactsContract.PhoneLookup供应商

You should have a look at the recommended ContactsContract.PhoneLookup provider

这是重新presents寻找了一个电话号码,例如来电显示的结果的表。要进行查找,你必须附加要找到CONTENT_FILTER_URI的数量。这个查询进行了高度优化。

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.

Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,...

这篇关于按电话号码检索联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆