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

查看:81
本文介绍了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所说,<manifest>下包含的所有<uses-permission>标签的数组,如果没有,则为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.

测试此示例的最小示例:

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) {
}

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

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