0

I know how to fetch all contacts as well as how to fetch the favorited contacts. Is there a way to combine the two and sort by favorites?

getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, "starred=?", new String[] {"1"}, <sort by favorites?>);
batman
  • 1,937
  • 2
  • 22
  • 41

1 Answers1

1

Try to use this query to get all contacts order by favorites and then by display name.

getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
null, 
null, 
null,
ContactsContract.Contacts.STARRED + " DESC, " + ContactsContract.Contacts.DISPLAY_NAME_PRIMARY + " ASC");
  • This works by getting all contacts sorted by favorites descending, however the other non favorite contacts are sorted in no particular order :( Also why does this work only with sort order DESC and not ASC ? – batman Apr 19 '16 at 04:37
  • If you want to query the favorites contacts first you should choose DESC order because Starred column is 1 for favorite and 0 for no no favorite. I'll change my answer to help you out with the ordering. – Moises Borges dos Anjos Apr 19 '16 at 11:14
  • Awesome, that worked perfectly. I think you missed a + after " DESC, " Kindly edit your answer to reflect that so that I can accept your answer as the solution :) – batman Apr 19 '16 at 12:12