According to the Android documentation it is possible to read the details from a specifically user-selected contact without the READ_CONTACTS permission. This should be possible by using the contacts URI, resulting from the "onActivityResult"-call. Querying this URI with a content resolver only gives me access to basic contact information though, as described in the ContactsContract.Contacts. I'm trying it using this (fairly standard) contact-picker code:
static final int REQUEST_SELECT_CONTACT = 1;
public void selectContact() {
// Start an activity for the user to pick a contact
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
if (intent.resolveActivity(getPackageManager()) != null) {
startActivityForResult(intent, REQUEST_SELECT_CONTACT);
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_SELECT_CONTACT && resultCode == RESULT_OK) {
// Get the URI and query the content provider for the contact data
contactUri = data.getData();
Cursor cursor = getContentResolver().query(contactUri, null, null, null, null);
// If the cursor returned is valid, retrieve the contact's details
if (cursor != null && cursor.moveToFirst()) {
int numberIndex = cursor.getColumnIndex(Phone.NUMBER);
int typeIndex = cursor.getColumnIndex(Phone.TYPE);
int idIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID);
int nameIndex =cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
String number = cursor.getString(numberIndex); // not accessible this way
String type= cursor.getString(typeIndex); // not accessible this way
String id = cursor.getString(idIndex); // accessible this way
String name = cursor.getString(nameIndex); // accessible this way
}
}
}
As an example for all contact data that should be somehow accessible I'm using the phone number and type. The index of these results in -1 as they are not present in the cursor. Yet somehow I need to get them, but I'm stuck on how to do that. Any help is appreciated!