0

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 = getContentResolver().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.

Pentium10
  • 204,586
  • 122
  • 423
  • 502
Andrew
  • 1

1 Answers1

0

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.

Pentium10
  • 204,586
  • 122
  • 423
  • 502