Android M: Can you programatically get the full se

2019-03-06 22:21发布

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.

2条回答
【Aperson】
2楼-- · 2019-03-06 23:05

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) {
}
查看更多
趁早两清
3楼-- · 2019-03-06 23:10

adb shell dumpsys package packagename will give you the permissions info requested by the app with packagename

查看更多
登录 后发表回答