从获取联系人列表中选择的电话号码没有READ_CONTACTS许可 [英] Get selected phone number from contacts list without READ_CONTACTS permission
问题描述
在我的应用我想给用户可能通过手动输入或从联系人列表中选择电话号码,以填补电话号码文本形式。有一件事我不明白的是,为什么我应该设置READ_CONTACTS权限如果himself.I用户选择联系人正在使用code如下:
In my app I want give user possibility to fill text form with phone number by manually typing it or selecting phone number from contacts list. One thing I don't understand is why I should set READ_CONTACTS permission if user select contact by himself.I am using code listed below:
-
要启动联系人活动:
To start Contacts activity:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK,
ContactsContract.Contacts.CONTENT_URI);
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST_CODE);
要处理意图
从数据的onActivityResult
:
Uri uri = data.getData();
if (uri != null) {
Cursor c = null;
try {
c = getContentResolver()
.query(
uri,
new String[] { ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.TYPE }, null, null,
null);
if (c != null && c.moveToFirst()) {
String number = c.getString(0);
int type = c.getInt(1);
showSelectedNumber(type, number);
}
} finally {
if (c != null) {
c.close();
}
}
}
和我的理解 getContentResolver()查询()
要求READ_CONTACTS许可获得的电话号码。
And as I understand getContentResolver().query()
requires READ_CONTACTS permission to obtain phone number.
我的问题:是否有可能以某种方式来处理意图进来的onActivityResult没有READ_CONTACTS
My question: is it possible somehow to process Intent that come in onActivityResult without READ_CONTACTS?
推荐答案
您不需要READ_CONTACTS实际。
You don't need READ_CONTACTS actually.
注:Android 2.3的(API 9级),表演联系人提供查询之前(如上面所示)要求您的应用程序声明READ_CONTACTS权限(请参见安全和权限)。然而,与Android 2.3,联系人开始/程序的人给予你的应用程序从联系人提供读取,当它返回一个结果的临时许可。临时许可只适用于请求的特定联系,所以你不能查询比意图的URI指定的其他联系人,除非你做声明READ_CONTACTS许可。
来源: http://developer.android.com/training/basics/意图/ result.html
这篇关于从获取联系人列表中选择的电话号码没有READ_CONTACTS许可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!