Getting a SINGLE cursor with full names and phone numbers

I want to create a single cursor containing both first name, last name, and phone number. These columns are not located in any of the containers available in the ContactsContract section, and the only way to get this information is to first get a cursor for names, and then get phone numbers by creating a separate cursor for each contact. This solution forces me to read the data into the local data structure, and not just use the adapter on the cursor and imposes a lot of overhead (about ~ 5 s ~ 140 contacts with phone numbers).

Is there a way to create two cursors and then join the tables? Or is there another way? I struggled with this issue for the last two days and read about everything that I found on google, but actually I can’t get anything working as I want. It may not be impossible, or is it?

Thanks in advance!

+5
source share
1 answer

You can get DISPLAY_NAMEand NUMBERfrom ContactsContract.CommonDataKinds.Phone. Try the following:

Uri uri = Phone.CONTENT_URI;
String[] projection = new String[]
                {Phone.DISPLAY_NAME, Phone.NUMBER, Phone.CONTACT_ID, Phone._ID}
Cursor contactsCursor = getContentResolver().query(uri, projection, null, null, null);
0
source

All Articles