Read Contacts without Permission?

2019-06-16 04:43发布

I want to read Contacts via Contacts Picker like this:

Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(contact, CONTACT_PICK_CODE);

If I get the Result, the intent.getData() contains an uri to lookup the Contact, but I need the permission READ_CONTACTS to to read it.

I thought it may be possible to recieve a Contact without this permission, similar to the CALL permission: If I want to make a call directly, I need it, but without it I can send a number to the phone app, and the user must click on the call button.
Is there a similar functionallity for READ_CONTACTS I'm not aware of?

2条回答
一纸荒年 Trace。
2楼-- · 2019-06-16 05:25

I hope there isn't such a functionality. The way you compare the "call without permissions" with the "read contacts without permissions" will be i think like the user has to enter the contactdata per hand.

The permissions have to be requested by app to protect the privacy of the user and helps to prevent data-collecting-apps.

If your app needs the contact list I think you can add the permission and the user will understand why you need it. If you don't need the contacts, you should not try the read the contacts.

An app always should only provide functionality that is really needed and nothing more. If a desktop-programm will collect data of what you are doing on computer, what games you are playing, whit whom you are mailing, etc. you will call it a trojan.

So just read the contacts if its really needed and then the user will give you the permissions therefore.

The permission.system of android mostly make sense ;)

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-06-16 05:28

You can retrieve Contact info without permissions and is something like you tell in the question.

In resume, you create an intent to pick a contact, this give you a URI (and temporally, also give you permissions to read it), then you use the URI to query to retrieve the data using Contact Provider API.

You can read more about it in Intents guide.

For example (from the guide):

static final int REQUEST_SELECT_PHONE_NUMBER = 1;

public void selectContact() {
    // Start an activity for the user to pick a phone number from contacts
    Intent intent = new Intent(Intent.ACTION_PICK);
    intent.setType(CommonDataKinds.Phone.CONTENT_TYPE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(intent, REQUEST_SELECT_PHONE_NUMBER);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_SELECT_PHONE_NUMBER && resultCode == RESULT_OK) {
        // Get the URI and query the content provider for the phone number
        Uri contactUri = data.getData();
        String[] projection = new String[]{CommonDataKinds.Phone.NUMBER};
        Cursor cursor = getContentResolver().query(contactUri, projection,
                null, null, null);
        // If the cursor returned is valid, get the phone number
        if (cursor != null && cursor.moveToFirst()) {
            int numberIndex = cursor.getColumnIndex(CommonDataKinds.Phone.NUMBER);
            String number = cursor.getString(numberIndex);
            // Do something with the phone number
            ...
        }
    }
}
查看更多
登录 后发表回答