Why is PackageInfo.requestedPermissions always null?
Posted
by Luke
on Stack Overflow
See other posts from Stack Overflow
or by Luke
Published on 2010-05-20T09:00:29Z
Indexed on
2010/05/20
9:10 UTC
Read the original article
Hit count: 364
android
|android-permissions
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.
© Stack Overflow or respective owner