Why is PackageInfo.requestedPermissions always null?
- by Luke
I'm trying to enumerate all the permissions used by all the installed packages, however when I check the requestedPermissions property for each of my installed packages it is always null. The following is the code that does this:
private HashMap<String, List<String>> buildMasterList() {
HashMap<String, List<String>> result = new HashMap<String, List<String>>();
List<PackageInfo> packages = getPackageManager().getInstalledPackages(PackageManager.GET_PERMISSIONS);
for (int i = 0; i < packages.size(); i++) {
String[] packagePermissions = packages.get(i).requestedPermissions;
Log.d("AppList", packages.get(i).packageName);
if (packagePermissions != null) {
for (int j = 0; j < packagePermissions.length; j++) {
if (!result.containsKey(packagePermissions[j])) {
result.put(packagePermissions[j], new ArrayList<String>());
}
result.get(packagePermissions[j]).add(packages.get(i).packageName);
}
}
else {
Log.d("AppList", packages.get(i).packageName + ": no permissions");
}
}
return result;
}
Edit: Oops! I just needed to pass the PackageManager.GET_PERMISSIONS flag to getInstalledPackages(). Updated the code snippet.