Given a permission name, how do I find the PermissionGroup?

青春壹個敷衍的年華 提交于 2019-12-12 11:20:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!