gpt4 book ai didi

java - 为什么在没有请求的情况下授予 WRITE_CONTACTS 权限?

转载 作者:行者123 更新时间:2023-12-04 10:35:59 25 4
gpt4 key购买 nike

我有 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_CONTACTSContacts 权限组的一部分。如果您已经在同一个组中请求了另一个权限,那么您实际上被授予了整个组的权限。因此,如果您已经请求并获得了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com