Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display the Contacts in sorting order ContactsContract.Contacts of Content Resolver

My intention is to display the contacts in sorting order using content resolver in android.

For that I'm writing:

Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID+ " = ?", new String[] { id }, null);

It needs that the last parameter in query method should not be null for sorting the elements by Name. Which part of code I have to replace the null parameter to achieve sorting by name?

like image 748
user1862773 Avatar asked Dec 11 '12 06:12

user1862773


People also ask

What is ContactsContract?

* ContactsContract defines an extensible database of contact-related. * information. Contact information is stored in a three-tier data model: * </p>

How do I select and display my phone number from a contact list on Android?

Open your Contacts app and tap the Options button (three dots), and select Contacts Manager. On the next screen, tap on Contacts to display from the menu. Next, if you only want contacts with a phone number, tap on Phone.


1 Answers

To sort result according to name use Phone.DISPLAY_NAME constant with ASC as last parameter to query method. do it as:

  Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                   null, 
                   ContactsContract.CommonDataKinds.Phone.CONTACT_ID+ " = ?",
                   new String[] { id },
                   ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME+" ASC");
like image 153
ρяσѕρєя K Avatar answered Sep 28 '22 05:09

ρяσѕρєя K