问题
I want to look up the permission group for a permission at runtime (to provide guidance in the UI about how to visit Settings and then enable the permission, after the user has checked the "never ask again" button on the prompt). So I need the human-readable name for the permission group, but all I have is the machine-readable fully qualified permission string (Manifest.permission.READ_PHONE_STATE
). Is there a way to do this?
回答1:
getPermissionInfo()
on PackageManager
returns a PermissionInfo
given the name of the permission. PermissionInfo
has a group
field that contains the group name ("android.permission-group.CALENDAR"
, a.k.a. Manifest.permission_group.CALENDAR
).
getPermissionGroupInfo()
on PackageManager
returns a PermissionGroupInfo
for that group name. On that, call loadLabel()
, supplying the PackageManager
as input, to get the human-readable name of the permission group.
来源:https://stackoverflow.com/questions/33837198/given-a-permission-name-how-do-i-find-the-permissiongroup