How can I sort RawContacts by their display name?

77 Views Asked by At

I need to read all contacts that belong to a specific account and sort them by their name.

And I would like to get them sorted in the Cursor rather then sort them after in an array.

This is what I currently do:

  1. I make a query in ContactsContract.RawContacts.CONTENT_URI and get their ContactsContract.RawContacts._ID

  2. make another query after it's data in ContactsContract.RawContacts.Entity.CONTENT_DIRECTORY based on the id and

  3. add it to an array. (it doesn't seem a great solution but I don't know about any other way to achieve this)

What am I missing?

1

There are 1 best solutions below

3
Surya Prakash Kushawah On

Run query like this

Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,
   ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1", 
   null, 
   "UPPER(" + ContactsContract.Contacts.DISPLAY_NAME + ") ASC");

Now cursor retrun shoted value