- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 2 台 API 28 设备和一个需要 WRITE_CONTACTS 权限的应用程序。我已经在 list 中添加了它 <uses-permission android:name="android.permission.WRITE_CONTACTS" />
.在我的应用程序的联系人列表中,当用户单击删除联系人时,我检查是否有权限,如果没有则请求。所以,在第一个设备中的方法
public static boolean checkWriteContactsPermission(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
return ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_CONTACTS) == PackageManager.PERMISSION_GRANTED;
}
返回 true,同时在第二个设备上返回 false。我没有提前请求此许可。为什么它的工作方式不同?
最佳答案
Android权限分为Permission groups , WRITE_CONTACTS
是 Contacts
权限组的一部分。如果您已经在同一个组中请求了另一个权限,那么您实际上被授予了整个组的权限。因此,如果您已经请求并获得了 READ_CONTACTS
的权限,您将免费获得 WRITE_CONTACTS
。
但是组可能会在不同的 Android 版本之间发生变化,请参阅链接文档中的这一部分:
If the app has already been granted another dangerous permission in the same permission group, the system immediately grants the permission without any interaction with the user. For example, if an app had previously requested and been granted the READ_CONTACTS permission, and it then requests WRITE_CONTACTS, the system immediately grants that permission without showing the permissions dialog to the user.
然后:
Caution: Future versions of the Android SDK might move a particular permission from one group to another. Therefore, don't base your app's logic on the structure of these permission groups.
For example, READ_CONTACTS is in the same permission group as WRITE_CONTACTS as of Android 8.1 (API level 27). If your app requests the READ_CONTACTS permission, and then requests the WRITE_CONTACTS permission, don't assume that the system can automatically grant the WRITE_CONTACTS permission.
关于java - 为什么在没有请求的情况下授予 WRITE_CONTACTS 权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60183415/
我有 2 台 API 28 设备和一个需要 WRITE_CONTACTS 权限的应用程序。我已经在 list 中添加了它 .在我的应用程序的联系人列表中,当用户单击删除联系人时,我检查是否有权限,如
因此,在我的应用程序中,通过单击按钮,我打开应用程序电话(可以调用...)。 我的问题是:我是否应该将 WRITE/READ_CONTACTS 权限放入我的 list 中,而我的应用程序仅通过其他应用
我是一名优秀的程序员,十分优秀!