问题描述
我有一个 HTC ONE M7 (GPE 4.2.2)和 HTC EVO 3D (4.0.3)的HTC Sense 3.6
HTC ONE 不需要
<使用许可权的android:NAME =android.permission.READ_CONTACTS/>
在 HTC EVO 3D 但是,下面的code抛出异常:
公共静态字符串getPhoneNumberFromIntent(上下文的背景下,意图数据)抛出SecurityException异常{
字符串contactNumber = NULL;
最后乌里contactUri = data.getData();
如果(contactUri!= NULL){
光标C = NULL;
尝试{
从联系人提供商//读取联系人号码
的String [] =投影新的String [] {} ContactsContract.CommonDataKinds.Phone.NUMBER;
C = context.getContentResolver()查询(contactUri,投影,NULL,NULL,NULL);
如果(C =空&放大器;!&放大器; c.moveToFirst()){
INT maxNumberLength = context.getResources()getInteger(R.integer.max_phone_number_cze)。
contactNumber = cutOnlyLastPhoneNumberDigits(c.getString(0),maxNumberLength);
}
} {最后
如果(C!= NULL){
c.close();
}
}
}
返回contactNumber;
}
-
java.lang.SecurityException异常:权限拒绝:阅读com.android.providers.contacts.HtcContactsProvider2
URI内容:从PID = 14938,UID //com.android.contacts/data/2158 = 10125要求android.permission.READ_CONTACTS
我已阅读,当用户通过手的接触appliaction被授予所需的权限。但是在某些手机上不起作用(HTC EVO 3D)。
这是为什么happending?有一种解决方法,例如在运行时,要求此权限的能力吗?
If the Uri
you are getting is coming from ACTION_PICK
or ACTION_GET_CONTENT
, whether or not you have temporary read permissions for that contact will vary by contact-picking app.
There is no requirement that all contact-picking apps grant you temporary read access to the contact. In fact, I am unclear if third-party contact managers would have the ability to grant you temporary read access to the contact.
You cannot ask for a permission at runtime.
Your choices are:
Always ask for
READ_CONTACTS
in the manifest. This ensures you can do what you want, at the cost of requesting another permission, one that prospective users might not like.Handle the
SecurityException
and simply do without the data that you are trying toquery()
, if that data is not essential.Write a separate app with the
READ_CONTACTS
permission that can serve as a "plugin" for your app, securely retrieving contact data on behalf of your main app. You can then route users who get theSecurityException
to install your contacts plugin. This is tricky to write without introducing security flaws, so I would encourage you to use either of the other options.
这篇关于有些手机需要许可READ_CONTACTS从联系人选择器阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!