According to the official docs at https://developer.android.com/guide/components/intents-common#Contacts
You can use a pick intent
public void selectContact() {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_SELECT_CONTACT);
}
}
For information about how to retrieve contact details once you have the contact URI, read Retrieving Details for a Contact. Remember, when you retrieve the contact URI with the above intent, you do not need the READ_CONTACTS permission to read details for that contact.
It points to https://developer.android.com/training/contacts-provider/retrieve-details for getting the details for the contact
When I follow the instructions in the link above I get
Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.contacts.ContactsProvider2 uri content://com.android.contacts/data from pid=5313, uid=10087 requires android.permission.READ_CONTACTS, or grantUriPermission()
I've tried to get the Contact details via
- Loader (as in the link instructions)
- getContentResolver().query()
- tried both with lookupKey and getting the contact id
Every way gives the requires android.permission.READ_CONTACTS Exception. Is there an example of this that works the way the documentation says?
Minimal, Complete, and Verifiable example at
https://github.com/aaronvargas/ContactsSSCCE
To test both with and without READ_CONTACTS, you'll have to change it in System App Settings
-Edit
Created issue on Android Issue Tracker at https://issuetracker.google.com/issues/118400813
Uri
that you get back fromACTION_PICK
. Please provide a minimal reproducible example, including the complete stack trace plus the code that generates the stack trace. – Shew"tried both with lookupKey and getting the contact id"
- not the way. you need to get thecontactUri
viadata.getData()
and query on that alone, without any selection – Puerperium