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?
* ContactsContract defines an extensible database of contact-related. * information. Contact information is stored in a three-tier data model: * </p>
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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With