为什么 WRITE_CONTACTS 未经请求就授予了权限?
Why WRITE_CONTACTS permission is granted without request?
我有 2 台 API 28 的设备和一个需要 WRITE_CONTACTS 权限的应用程序。我已将其添加到清单 <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;
}
return true,同时在第二个设备上返回 false。我没有提前请求此许可。为什么它的工作方式不同?
Android权限分为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.
我有 2 台 API 28 的设备和一个需要 WRITE_CONTACTS 权限的应用程序。我已将其添加到清单 <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;
}
return true,同时在第二个设备上返回 false。我没有提前请求此许可。为什么它的工作方式不同?
Android权限分为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.