Raf*_*l T 10 permissions android contacts android-contentprovider
我想通过Contacts Picker这样的方式阅读Contacts :
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
startActivityForResult(contact, CONTACT_PICK_CODE);
Run Code Online (Sandbox Code Playgroud)
如果我得到结果,则intent.getData()包含uri查找联系人的内容,但我需要获得READ_CONTACTS读取权限.
我认为有可能在没有此权限的情况下接收联系人,类似于CALL权限:如果我想直接拨打电话,我需要它,但没有它我可以向手机应用程序发送一个号码,用户必须点击在通话按钮上.我不知道
有类似的功能READ_CONTACTS吗?
Pho*_*ixS 12
您可以在没有权限的情况下检索联系信息,就像您在问题中所说的那样.
在简历中,您创建了一个选择联系人的意图,这为您提供了一个URI(并且在时间上也授予您阅读权限),然后使用URI查询以使用Contact Provider API检索数据.
您可以在Intents指南中阅读更多相关信息.
例如(来自指南):
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
...
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3231 次 |
| 最近记录: |