5

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?

esong
  • 260
  • 1
  • 11

1 Answers1

6

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Loadlabel() always return localized string, but i want non localized string. Any API is available to retrieve non localized string. – parul Jun 23 '17 at 07:38
  • @parul: What would a "non localized string" be? – CommonsWare Jun 23 '17 at 11:42
  • It does not work in Android 10, it throws "NameNotFoundException" – Zijian Jan 13 '20 at 07:05
  • @Zijian: I do not know what "it" is. Perhaps you are requesting a permission group that does not exist on Android 10. – CommonsWare Jan 13 '20 at 11:59
  • @CommonsWare `final PackageManager pm = App.app.getPackageManager(); final PermissionGroupInfo info = pm.getPermissionGroupInfo(grpupName, 0); return info.loadLabel(pm);` "pm.getPermissionGroupInfo" throws NameNotFoundException in Android 10. It works well in other Android versions – Zijian Jan 15 '20 at 02:47
  • 1
    @Zijian: My guess is that what you are seeing is a refined version of [this bug report](https://issuetracker.google.com/issues/139012029), marked as "working as intended". – CommonsWare Jan 15 '20 at 12:05