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?

Answers


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.


Need Your Help

Sinew (ruby web scraper) example does not work on my machine

ruby web-crawler web-scraping nokogiri popen

I'm trying to run the sample from the sinew source code, but it's not working on my machine. Here is the sample (taken directly from their github):

How to Link the CSS in Eclipse?

java css eclipse jsp

I am facing problem while linking the css file in jsp page.