PhoneLookup.CONTENT_FILTER_URI两次返回同一联系人 [英] PhoneLookup.CONTENT_FILTER_URI returns twice the same contact

查看:1334
本文介绍了PhoneLookup.CONTENT_FILTER_URI两次返回同一联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我下面的code,我试图得到一个特定的电话号码的所有联系人。

但它看起来像我总是得到一些接触ID的更多然后一次。
特别是我有同一个电话号码2的接触,我也得到3接触式ID的。他们中的一个两次(相同的ID)

什么想法?

感谢

 光标contactLookupCursor =
localContentResolver.query(
    Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,Uri.en code(requestedPhone))
                    新的String [] {} PhoneLookup._ID,
                    空值,
                    空值,
                    空值);如果(contactLookupCursor!= NULL)
{
    的System.out.println(contactLookupCursor.getCount =+ contactLookupCursor.getCount()); //这里我得到3
    如果(contactLookupCursor.moveToFirst())
    {
        做
        {
            INT参数:columnIndex = contactLookupCursor.getColumnIndex(PhoneLookup._ID);
            如果(参数:columnIndex> = 0)
            {
                字符串的ContactID = contactLookupCursor.getString(参数:columnIndex);
                的System.out.println(的ContactID =+的ContactID); //这里我得到12然后13,然后再13
            }
        }
        而(contactLookupCursor.moveToNext());
    }
    contactLookupCursor.close();
}


解决方案

如果您提供的非规范化的电话号PhoneLookup.CONTENT_FILTER_URI那么这将是<强>在两个位置匹配的电话号码的数据记录表。

  1匹配在记录列号码号码。
1匹配在记录列normalized_numbernormalized_number。

如果您提供的数=49177123456若干== normalized_number

这种情况下 PhoneLookup.CONTENT_FILTER_URI将搜索仅在normalized_number列 电话表。


您也可以使用 CommonDataKinds.Phone 而不是PhoneLookup。

这样,你没有得到重复的结果是否提供的电话号码是归与否:

 串号=0177123456;
URI URI = Uri.withAppendedPath(android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,Uri.en$c$c(number));
光标rcursor = getContentResolver()查询(URI,
                                        新的String [] {} ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
                                        NULL,NULL,NULL);

我猜PhoneLookup的奇怪的行为是一个错误。

也许PhoneLookup更高性能比CommonDataKinds.Phone:


  

类概述:[...]这个查询是高度优化。的http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html


有对CommonDataKinds.Phone没有这样的说法。

in my code below, i am trying to get all contacts with a specific phone number.

however it looks like i always get some of the contacts id more then once. specifically i have 2 contacts with the same phone number, and i get 3 contact Id's. one of them twice (the same ID)

any ideas?

thanks

Cursor contactLookupCursor =  
localContentResolver.query(
    Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(requestedPhone)), 
                    new String[] {PhoneLookup._ID}, 
                    null, 
                    null, 
                    null);

if (contactLookupCursor != null)
{
    System.out.println("contactLookupCursor.getCount = "+contactLookupCursor.getCount()); // here i get 3
    if(contactLookupCursor.moveToFirst())
    {
        do
        {
            int ColumnIndex = contactLookupCursor.getColumnIndex(PhoneLookup._ID);
            if(ColumnIndex >= 0)
            {
                String contactId = contactLookupCursor.getString(ColumnIndex);
                System.out.println("contactId="+contactId);// here i get 12 then 13 then 13 again
            }
        }
        while (contactLookupCursor.moveToNext());
    }
    contactLookupCursor.close();
}

解决方案

If you provide a non-normalized phone number to PhoneLookup.CONTENT_FILTER_URI then it will be matched at two positions in the data record table of phone numbers.

1 match for number with column "number" in record.
1 match for normalized_number with column "normalized_number" in record.

If you provide number = "+49177123456" then number == normalized_number .

In this case PhoneLookup.CONTENT_FILTER_URI will only search in the "normalized_number" column of the phone table.


You can alternatively use CommonDataKinds.Phone instead of PhoneLookup.

This way you don't get duplicate results whether the provided phone number is normalized or not:

String number = "0177123456";
Uri uri =     Uri.withAppendedPath(android.provider.ContactsContract.CommonDataKinds.Phone.CONTENT_FILTER_URI,Uri.encode(number));
Cursor rcursor = getContentResolver().query(uri,
                                        new String[] { ContactsContract.CommonDataKinds.Phone.CONTACT_ID },
                                        null,null,null);

I guess the strange behavior of PhoneLookup is a bug .

But maybe PhoneLookup is more performant than CommonDataKinds.Phone:

Class Overview: [...] This query is highly optimized. http://developer.android.com/reference/android/provider/ContactsContract.PhoneLookup.html

There is no such statement for CommonDataKinds.Phone.

这篇关于PhoneLookup.CONTENT_FILTER_URI两次返回同一联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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