Is there a way to get all the phone numbers for all contacts without a separate request for each contact? (using Android 2.0+). This is very slow, if you have more than 100 contacts (unsuitable for use on low-end phones), I wondered if I could make a more efficient request.
Currently, I get a cursor with all valid ContactsContract.Contacts.IN_VISIBLE_GROUP contacts, and then a separate request for each contact to get all its numbers.
A snippet from the Contacts list just enter a name and search key:
Uri uri = ContactsContract.Contacts.CONTENT_URI; String[] projection = new String[] { ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.LOOKUP_KEY};
Then each contact uses a search key.
Uri lookupUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey); Uri res = ContactsContract.Contacts.lookupContact(contentResolver, lookupUri); String[] projection = new String[]{ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.HAS_PHONE_NUMBER};
...
Cursor phones = contentResolver.query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, phoneProjection, selection, selectionArgs, sortOrder);
source share