【问题标题】:Android phone lookup (PhoneLookup.CONTENT_FILTER_URI) returns the same contact multiple timesAndroid 手机查找 (PhoneLookup.CONTENT_FILTER_URI) 多次返回同一个联系人
【发布时间】:2015-03-03 12:59:19
【问题描述】:

我正在使用here 所述的电话号码查找联系人

Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(givenNumber));

final Account availableAccounts[] = AccountManager.get(context).getAccountsByType(Constants.ACCOUNT_TYPE);
Uri rawContactUri = ContactsContract.RawContacts.CONTENT_URI;

Cursor phoneContact = context.getContentResolver().query(
    lookupUri
    , null //new String[]{ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.DISPLAY_NAME}
    ,null,null, null);

DatabaseUtils.dumpCursor(phoneContact);

while (phoneContact.moveToNext()) {
    long contactID = phoneContact.getLong(phoneContact.getColumnIndex(ContactsContract.PhoneLookup._ID));            
}
phoneContact.close();

出于调试目的,投影设置为 null。 从DatabaseUtils.dumpCursor(phoneContact); 的结果可以看出,我多次收到相同的联系人:

>>>>> Dumping cursor android.content.ContentResolver$CursorWrapperInner@1517c824
0 {
number=+00001122334
photo_uri=content://com.android.contacts/display_photo/6
send_to_voicemail=0
lookup=32i415560988b4aed0e.32i636352790bf3a3a6.3789r869-2D4531433931.3746i15
display_name=John Doe
last_time_contacted=1425383680707
has_phone_number=1
in_visible_group=1
photo_file_id=6
label=null
starred=0
normalized_number=+00001122334
photo_thumb_uri=content://com.android.contacts/contacts/212/photo
photo_id=1427
in_default_directory=1
custom_ringtone=null
_id=212
type=2
times_contacted=44
}
1 {
number=0001122334
photo_uri=content://com.android.contacts/display_photo/6
send_to_voicemail=0
lookup=32i415560988b4aed0e.32i636352790bf3a3a6.3789r869-2D4531433931.3746i15
display_name=John Doe
last_time_contacted=1425383680707
has_phone_number=1
in_visible_group=1
photo_file_id=6
label=null
starred=0
normalized_number=+27001122334
photo_thumb_uri=content://com.android.contacts/contacts/212/photo
photo_id=1427
in_default_directory=1
custom_ringtone=null
_id=212
type=2
times_contacted=44
}
2 {
number=0001122334
photo_uri=content://com.android.contacts/display_photo/6
send_to_voicemail=0
lookup=32i415560988b4aed0e.32i636352790bf3a3a6.3789r869-2D4531433931.3746i15
display_name=John Doe
last_time_contacted=1425383680707
has_phone_number=1
in_visible_group=1
photo_file_id=6
label=null
starred=0
normalized_number=+27001122334
photo_thumb_uri=content://com.android.contacts/contacts/212/photo
photo_id=1427
in_default_directory=1
custom_ringtone=null
_id=212
type=2
times_contacted=44
}
<<<<<

注意:出于隐私原因,我已经更换了电话号码。联系人之间的唯一区别是第一个是国际格式(+00)的号码,而其余的是本地格式。

如果有人可以对这种行为有所了解,与我的问题相同但细节较少的问题是here,但也没有答案。类似的问题包括人们没有检查 mime_types,example

谢谢。

【问题讨论】:

    标签: android android-contentprovider contacts android-contacts


    【解决方案1】:

    在此处查看答案: https://stackoverflow.com/a/30249338/819355.

    基本上,您可以使用CommonDataKinds.Phone.CONTENT_FILTER_URI 而不是PhoneLookup.CONTENT_FILTER_URI 来获得单个结果。

    【讨论】:

    • CommonDataKinds.Phone 导致 E/execption: Invalid column number
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多