The GiG
The GiG

Reputation: 2611

Android fetch all contacts duplicated names

Im using this code:

protected String getContactInfo() {
         Cursor cursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, null, null, null, null);
         String str = "";
         while (cursor.moveToNext()) {
          str += cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)) + ", ";
        }
        cursor.close();
        return str;
}

and after execution the string that this method returns is Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test1, Test2, Test2, Test2, Test2, Test2, Bob, Bob, Bob, Bob,

When I have only 3 contacts in the phonebook Test1, Test2, Bob

Why would this happen?

Upvotes: 1

Views: 823

Answers (1)

Kri
Kri

Reputation: 1856

try this...

replace the query parameter with URI...

Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

you are trying to fetch the name from ContactsContract.Contacts.CONTENT_URI and you are firing the query on ContactsContract.Data.CONTENT_URI.

Upvotes: 4

Related Questions