Android: Obtain the permissions of an application.
Log outputs the permissions of an APP.
PackageManager pm = context. getPackageManager (); PackageInfo pi; try {// parameter 2 must be PackageManager. GET_PERMISSIONS pi = pm. getPackageInfo (packageName, PackageManager. GET_PERMISSIONS); String [] permissions = pi. requestedPermissions; if (permissions! = Null) {for (String str: permissions) {Log. I (TAG, str) ;}} catch (NameNotFoundException e) {e. printStackTrace ();}
In the above Code, packageName is the package name of the target APP.
Returns the permission information of an APP in the List set.
Based on the above Code, modify it as follows:
List
permissionInfoList = new ArrayList
();PackageManager pm = context.getPackageManager();PackageInfo pi;try { pi = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); String[] permissions = pi.requestedPermissions; if(permissions != null){ for(String str : permissions){ PermissionInfo permissionInfo = context.getPackageManager().getPermissionInfo(str, 0); permissionInfoList.add(permissionInfo); } }} catch (NameNotFoundException e) { e.printStackTrace();}return permissionInfoList;
Based on the above code, you can obtain more detailed permission information.
For more information, seegetAppPermissionListAndshowAppPermissionListMethod.