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?
try this…
replace the query parameter with URI…
you are trying to fetch the name from
ContactsContract.Contacts.CONTENT_URIand you are firing the query onContactsContract.Data.CONTENT_URI.