android判断应用是否有某个权限

1) 判断应用是否具有某个权限

PackageManager pm = getPackageManager();
        boolean permission = (PackageManager.PERMISSION_GRANTED == 
                pm.checkPermission("android.permission.RECORD_AUDIO", "packageName"));
        if (permission) {
            showToast("有这个权限");
        }else {
            showToast("木有这个权限");
        }


2)获取某个应用的权限清单

try {
            PackageInfo pack = pm.getPackageInfo("packageName",PackageManager.GET_PERMISSIONS);</span>
            String[] permissionStrings = pack.requestedPermissions;
            showToast("权限清单--->" + permissionStrings.toString());
        } catch (NameNotFoundException e) {
            e.printStackTrace();
        }

permissionStrings 是一个这样的字符串数组

[android.permission.INTERNET, 
         android.permission.READ_PHONE_STATE, 
         android.permission.READ_CONTACTS, 
         ……
         android.permission.READ_EXTERNAL_STORAGE, 
         android.permission.READ_CALL_LOG, 
         android.permission.WRITE_CALL_LOG]

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。