取得联系通过在Android手机号码 [英] Get Contact by Phone number on Android
问题描述
我知道我怎样才能在Android中的所有联系人,以及如何让自己的手机号码。
I know how I can get all contacts in Android , and how to get their phone number.
我似乎无法弄清楚是如何得到的联系人电话号码......
What I cant seem to figure out is how to get a contact by phone number...
这是我目前的一块code我写了要测试的电话号码是可用的:
This is my current piece of code I wrote to test which phone numbers are available:
// Create a cursor
Cursor cursor = Base.contentResover().query(Phone.CONTENT_URI, null, null,
null, null);
if (cursor.moveToNext()) {
Log.d("CALLOG", cursor.getString(cursor.getColumnIndexOrThrow(Phone.NUMBER)));
}
现在的问题是,我只得到了几个电话号码回来,而我希望让所有......我究竟做错了什么?
The problem is that i only get a few phone numbers returned, while i expect to get all... What am I doing wrong?
推荐答案
我不认为有什么不对,你已经粘贴代码段。 尝试使用while循环来记录所有的电话号码。
I dont think there is anything wrong with the snippet that you had pasted. Try using a while loop to LOG all the phone numbers.
对于您的要求使用下面的代码片段获取联系人通过电话Number.Try
Regarding your requirement to fetch a contact by Phone Number.Try using the following snippet
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(phoneNumber));
resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME,PhoneLookup._ID...
使用的_ID来确定接触。
Use the _ID to determine the contact.
为什么要使用,而不是电话PhoneLookup?
Why to use PhoneLookup instead of Phone?
-
该PhoneLookup是高度优化 在它的搜索条件。
The PhoneLookup is highly optimised in terms of its searches.
电话号码可以在输入
联系人数据库中包含填充物(,), - 等PhoneLookup
有助于分离这些填料并比较仅电话号码。
Phone numbers can be entered in the
contacts database with fillers like "(",")","-" etc PhoneLookup
helps to decouple these fillers and compare only the phone number.
从比较的电话值不会把你的任何结果。
Comparing the values from Phone will not fetch you any result.
它提供了多种其他的手机 一些相关的信息。 (HAS_PHONE_NUMBER,TIMES_CONTACTED,DISPLAY_NAME 等)
It provides various other phone number related info. (HAS_PHONE_NUMBER,TIMES_CONTACTED,DISPLAY_NAME etc)
希望有所帮助。让我知道你需要什么。
Hope that helps. Let me know if you need anything else.
这篇关于取得联系通过在Android手机号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!