0

Given:

Uri contactLookupURI = ContactsContract.Contacts.getLookupUri(contactID, lookupKey);

How do I use this to get a contact's details such as phone, email, etc?

I tried:

String[] CDETAIL_PROJECTION = {
            ContactsContract.Contacts._ID,
            ContactsContract.Contacts.DISPLAY_NAME_PRIMARY,
            ContactsContract.CommonDataKinds.Phone.NUMBER,
            ContactsContract.CommonDataKinds.Email.ADDRESS,
    };


Cursor detail_cursor = getContext().getContentResolver().query(contactLookupURI, CDETAIL_PROJECTION, null, null, null);

But I get an error saying "Invalid column: data1" which I guess refers to Phone.NUMBER field. This might be because it's referring to the Contacts table which doesn't have that field?

According to other answers, I can use the _ID to get the contact details but I want to use the URI only.

Also, can you tell me what

ContactsContract.Contacts.lookupContact() 

does? The documentation illustrates that it gives me the Content URI but how's it any different than the Lookup URI?

1 Answers1

0

You have getting Invalid column: data1 because ContactsContract.CommonDataKinds.Phone.NUMBER and ContactsContract.CommonDataKinds.Email.ADDRESS both have same value that's data1. you can not directly get this information.

here is solution for get he email and Number from user https://stackoverflow.com/a/40540640/2941375

MJM
  • 5,119
  • 5
  • 27
  • 53