0

Is it possible to retrieve all the phone numbers with just one query(it's ok even if it's a bit slow)?

I found many topics that suggest to make query for the contact list and then a query for each contact but that's really slow.

The only solutions that I found with one query, retrieve just the main number. I need all the numbers of each contact plus the type.

Thanks.

A._
  • 23
  • 6
  • Possible duplicate of [Read all contact's phone numbers in android](http://stackoverflow.com/questions/2356084/read-all-contacts-phone-numbers-in-android) – OneCricketeer Nov 10 '15 at 12:49

1 Answers1

0

try this

 Cursor cursor = getContentResolver()
 .query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
 new String[] {Phone._ID, Phone.DISPLAY_NAME, Phone.NUMBER}, null, null,  Phone.DISPLAY_NAME + " ASC");
  • Is it also possible to avoid duplicates? I'm getting items with exactly the same name and number. – A._ Nov 10 '15 at 15:26
  • yes you can remove the duplicates while (cursor.moveToNext()) { phoneNumber = phones.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); name = phones.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); int flag = 0 if(list.size() == 0){ list.add(new ProfileBean(name, phoneNumber)); } for(int i=0;i – Mostafa Darwish Nov 11 '15 at 11:40