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]

 

posted on 2014-12-24 22:45  I love Android  阅读(4305)  评论(0编辑  收藏  举报