在我的应用程序中,我想让用户能够通过手动输入或从联系人列表中选择电话号码来填写文本表单。我不明白的一件事是,如果用户自行选择contact,我为什么要设置READ_CONTACTS
权限,我正在使用下面列出的代码:
Intent
的onActivityResult
数据:
uri Uri = data.getData();if (uri != null) {游标c= null;尝试{c= getContentResolver() .query( uri,新String[] { ContactsContract.CommonDataKinds.Phone.TYPE },null,null);if (c != null & c.moveToFirst()) { String number = c.getString(0);int类型= c.getInt(1);showSelectedNumber(类型,数);}最后{ if (c != null) { c.close();}据我所知,getContentResolver().query()
需要READ_CONTACTS
许可才能获得电话号码。
我的问题:是否可能以某种方式处理onActivityResult中没有READ_CONTACTS
的意图
发布于 2014-05-15 20:26:27
你其实不需要READ_CONTACTS。
Note: Before Android 2.3 (API level 9), performing a query on the Contacts Provider (like the one shown above) requires that your app declare the READ_CONTACTS permission (see Security and Permissions). However, beginning with Android 2.3, the Contacts/People app grants your app a temporary permission to read from the Contacts Provider when it returns you a result. The temporary permission applies only to the specific contact requested, so you cannot query a contact other than the one specified by the intent's Uri, unless you do declare the READ_CONTACTS permission.
来源:http://developer.android.com/training/basics/intents/result.html
发布于 2014-04-23 04:43:02
如果不在清单文件中授予READ_CONTACTS
权限,您就无法访问Android联系人数据库。
Android移动操作系统使用许可系统来帮助确保应用程序行为正常。该系统允许应用程序请求访问设备上的功能,这些功能可以使用电力、访问敏感数据并支付费用。
发布于 2014-04-23 04:55:55
您应该在清单文件中写入权限,然后您只能从文件中读取联系人。
https://stackoverflow.com/questions/23244266
复制相似问题