Android: Get localized permission group names

2019-06-26 06:29发布

问题:

In marshmallow's runtime permission, user can choose "never ask again" in permission requests. In this case, we have to redirect user to app settings to let them enable the permissions for the app. Also, Android permissions are group based, it will be very handy to display names of the permission groups that the app needs before we send the user to the settings.

I've seen the strings in android.Manifest such as "android.permission-group.LOCATION". Is it possible to get the permission group names programmatically?

回答1:

getPermissionGroupInfo() on PackageManager returns a PermissionGroupInfo for that group name (android.permission-group.LOCATION). On that, call loadLabel(), supplying the PackageManager as input, to get the human-readable name of the permission group. This should be localized for the user's chosen device locale.