开发者

Android Contacts Query Gets Duplicates

I'm trying to get all of the phone numbers for a contact. When I query the numbers associated with a contact with a cursor, I get duplicates of every number. After snooping around I believe that this is because of the Linked Profiles (i.e. Google profile and Phone Contacts profile). Here is my code for pulling out the numbers:

Cursor cursor = ge开发者_开发知识库tContentResolver().query(
     Phone.CONTENT_URI, 
     new String[]{PhoneLookup.NUMBER},
     Phone.CONTACT_ID + "=?",
     new String[]{id}, null);
while(cursor.moveToNext()) {
     String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
     Toast.makeText(getApplicationContext(), phoneNumber, Toast.LENGTH_LONG).show();
}
cursor.close();

Is there a way to limit this query to a certain profile? Thanks in advance. I've searched on this for awhile and been unable to find any solutions.


I was struggling with similar stuff lately (eg. missing the group by clause), and I managed to workaround by inserting the data from ContentProvider into a temp table and querying the table for results.

The story is that the data behind a ContentProvider might not be a database. It can be XML, JSON, FileSystem etc... So these do not have the Group By option, and therefor they left it out. You also can't suppose always that count(_id) will work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜