1

I am aware about the Android Contact picker which gives us the URI of any selected Contact.

The URI looks like this: content://com.android.contacts/contacts/lookup/0r7-2C46324E483C324A3A484634/7

I need to get the URIs of all the contacts (something like a 'URI array') in the phone. Can someone help me out over doing this?

code monkey
  • 2,094
  • 3
  • 23
  • 26

1 Answers1

5

You can get all Contacts with the following query : cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); Where cr is a ContentResolver.

Have a look here : get all contacts.

Community
  • 1
  • 1
grattmandu03
  • 1,266
  • 2
  • 13
  • 32
  • Thanks. I know that I can get Contact information (Name, phone number, mail ...) with this query. But I do not know how to get the URI of the contact. – code monkey Jul 11 '13 at 14:49
  • 1
    To have the contact URI, you just need to append the contact id with the ContactsContract.Contacts.CONTENT_URI like this : Uri contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, contactId); – grattmandu03 Jul 11 '13 at 15:14
  • Tanks! Sorry for the question. But can you tell me how to get the ID of a User? I tried `c.getColumnIndex(ContactsContract.Data.Contact_ID)` but it seems that this is wrong – code monkey Jul 15 '13 at 08:00
  • 2
    String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); I took this line from the link in my answer, so I guess it works. – grattmandu03 Jul 15 '13 at 10:00