Android M:您能否以编程方式获得应用所需的全套权限? [英] Android M: Can you programatically get the full set of permissions an app would like?

查看:30
本文介绍了Android M:您能否以编程方式获得应用所需的全套权限?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与应用当前获得的授权不同 - 这可能是它总共想要的授权的一个子集.

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.

这个展示了如何获得当前授予的集合.在 Android M 之前,这是完整的设置,因为除非用户授予了它想要的所有功能,否则它不会被安装.然而,在 Android M 下,用户可以选择授予哪个,并在安装后随时更改.我想要应用程序清单中列出的全套应用程序.

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.

推荐答案

正如@CommonsWare 评论的那样,PackageInfo.requestedPermissions 包含一个 "Array 下的所有 标签,如果没有,则为 null."

As @CommonsWare commented, PackageInfo.requestedPermissions contains an "Array of all <uses-permission> tags included under <manifest>, or null if there were none."

我在运行 Android M 的设备上对此进行了测试,得到的输出包括来自所有 <uses-permission> 标签的权限,无论这些权限是否已被授予,正如预期的那样.

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.

用于测试的最小示例:

try {
    PackageInfo pi = getPackageManager().getPackageInfo("com.example.foo", PackageManager.GET_PERMISSIONS);
    for (String perm : pi.requestedPermissions) {
        Log.e("Foo", perm);
    }
} catch (Exception e) {
}

这篇关于Android M:您能否以编程方式获得应用所需的全套权限?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆