This isn't the same as the ones an app has been currently granted - that might be a subset of the ones it would like in total.
This shows how to get the currently granted set. Before Android M, that's the full set because it wouldn't have been installed unless the user had granted all of the ones it wanted. Under Android M however, the user can choose which to grant, and change at any time after installation. I'd like the full set an app would like as listed in it's manifest.
As @CommonsWare commented, PackageInfo.requestedPermissions
contains an "Array of all <uses-permission>
tags included under <manifest>
, or null if there were none."
I've tested this on a device running Android M, and the output I got included the permissions from all <uses-permission>
tags regardless of whether those permissions had been granted or not, just as expected.
A minimal example for testing this:
try {
PackageInfo pi = getPackageManager().getPackageInfo("com.example.foo", PackageManager.GET_PERMISSIONS);
for (String perm : pi.requestedPermissions) {
Log.e("Foo", perm);
}
} catch (Exception e) {
}
adb shell dumpsys package packagename
will give you the permissions info requested by the app with packagename