1

Hi am using this code for getting contacts from Android contact list last parameter in below method i.e null

Can anyone tell me how to sort contact list alphabatically? which parameter I passed so I will get desired output:

Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
            null, null, null);
abierto
  • 1,447
  • 7
  • 29
  • 57

2 Answers2

5

You can sort contact alphabetically using

Cursor cursor = getContentResolver.query(Phone.CONTENT_URI, null, null, null, Phone.DISPLAY_NAME + " ASC");
A--C
  • 36,351
  • 10
  • 106
  • 92
Martin
  • 2,146
  • 4
  • 21
  • 32
0

Use Upper() as it will work for both lower as well as upper case contact name.

    ContentResolver cr = getContentResolver();

    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,
            null, null,  "upper("+ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC");
Akhilesh Dhar Dubey
  • 2,152
  • 2
  • 25
  • 39