以编程方式从android中的manifest.xml检索权限 [英] Programmatically retrieve permissions from manifest.xml in android

查看:180
本文介绍了以编程方式从android中的manifest.xml检索权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须以编程方式从android应用程序的manifest.xml中检索权限,我不知道该怎么做。

I have to programmatically retrieve permissions from the manifest.xml of an android application and I don't know how to do it.

我读这里的帖子但我并不完全满意答案。
我想android API中应该有一个类允许从清单中检索信息。

I read the post here but I am not entirely satisfied by the answers. I guess there should be a class in the android API which would allow to retrieve information from the manifest.

谢谢。

推荐答案

您可以使用此方法:

//for example, permission can be "android.permission.WRITE_EXTERNAL_STORAGE"
public boolean hasPermission(String permission) 
{
    try {
        PackageInfo info = getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
        if (info.requestedPermissions != null) {
            for (String p : info.requestedPermissions) {
                if (p.equals(permission)) {
                    return true;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

这篇关于以编程方式从android中的manifest.xml检索权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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