Get permission information programmatically

Is there anyway in android sdk where they provide information for a specific resolution? As with google, whenever you click on a permission, you can read what that permission does. I have this function to return me specific permissions for the application

public static List<String> getAppPermissions(Context context, String packageName) { try { PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); return Arrays.asList(info.requestedPermissions); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return new ArrayList<>(); } } 

By this code, I get only permission names, but I'm wondering if there are any api that return permissions and their data.

+5
source share
1 answer

to answer my question PermissionInfo is actually the right class to get a description of any android permission , for example:

 @Nullable public static PermissionInfo getPermissionInfo(@NonNull Context context, @NonNull String permission) { try { return context.getPackageManager().getPermissionInfo(permission, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return null; } 

the above method will return an instance of PermissionInfo if it can parse the permission name given to it, and then you can simply call loadDescription to load the permission description.

0
source

All Articles