A simple function that returns all the permissions that have been requested and granted for a given package could look like this:
List<String> getGrantedPermissions(final String appPackage) {
List<String> granted = new ArrayList<String>();
try {
PackageInfo pi = getPackageManager().getPackageInfo(appPackage, PackageManager.GET_PERMISSIONS);
for (int i = 0; i < pi.requestedPermissions.length; i++) {
if ((pi.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
granted.add(pi.requestedPermissions[i]);
}
}
} catch (Exception e) {
}
return granted;
}
Note that this requires API level 16 or above, but that should hopefully not be an issue these days.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…