1

I am trying to extract a list of contacts from Android, the list returns correctly. The returned list is sorted in alphabetical order however the upper case letters are first followed by the lower case characters. Example. ABCDEFGHIJ.....abcdef

The following is the cursor I am using:

Cursor cursor = contentResolver.query(CONTENT_URI, null,null, null, "display_name ASC");
the_big_blackbox
  • 1,056
  • 2
  • 15
  • 35

2 Answers2

4

use display_name COLLATE NOCASE ASC to order the record case insensitive.

vims liu
  • 643
  • 1
  • 9
  • 20
0

Use My code

 private void getContactList() {
    ContentResolver cr = getContentResolver();

    Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, PROJECTION, null, null,
            "display_name COLLATE NOCASE ASC");
    if (cursor != null) {
        HashSet<String> mobileNoSet = new HashSet<String>();
        try {
            final int nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
            final int numberIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);

            String name, number;
            while (cursor.moveToNext()) {
                name = cursor.getString(nameIndex);
                number = cursor.getString(numberIndex);
                number = number.replace(" ", "");
                if (!mobileNoSet.contains(number)) {
                    contactList.add(new Contact(name, number));
                    mobileNoSet.add(number);
                }
            }
        } finally {
            cursor.close();
        }
    }
}
jay patoliya
  • 611
  • 7
  • 8