阅读未经允许的联系人? [英] Read Contacts without Permission?

查看:99
本文介绍了阅读未经允许的联系人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想这样通过Contacts Picker阅读联系人:

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);

如果我得到结果,则intent.getData()包含一个uri来查找联系人,但是我需要获得权限READ_CONTACTS才能读取它.

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.

我认为没有此权限也可以接收联系人,类似于CALL权限:如果我想直接拨打电话,我需要它,但是如果没有它,我可以向电话应用程序发送号码,并且用户必须单击呼叫"按钮.
我不知道的READ_CONTACTS是否具有类似的功能?

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?

推荐答案

您可以在没有权限的情况下检索联系人信息,就像您在问题中所讲的那样.

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

在简历中,您将创建一个选择联系人的意图,这将为您提供一个URI(并且在时间上也为您提供了读取它的权限),然后您可以使用URI通过联系提供商API .

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.

例如(来自指南):

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
            ...
        }
    }
}

这篇关于阅读未经允许的联系人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆