Log output permissions that an app has
PackageManager pm = context.getPackageManager();PackageInfo pi;try { // 参数2必须是PackageManager.GET_PERMISSIONS pi = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); String[] permissions = pi.requestedPermissions; ifnull){ for(String str : permissions){ Log.i(TAG, str); } catch (NameNotFoundException e) { e.printStackTrace();}
In the code above, PackageName is the package name of the target app.
Returns the permission information for an app with the list collection
Based on the above code, modify the following method:
new ArrayList<PermissionInfo>();PackageManager pm = context.getPackageManager();PackageInfo pi;try { pi = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); String[] permissions = pi.requestedPermissions; ifnull){ for(String str : permissions){ 0); permissionInfoList.add(permissionInfo); } catch (NameNotFoundException e) { e.printStackTrace();}return permissionInfoList;
Based on the code above, you get richer permission information.
Specific information can be found in the page getAppPermissionList
and showAppPermissionList
methods.
Android: Get app-owned permissions