码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2014-12-25 00:08:32      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:

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]

 

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

标签:

原文地址:http://www.cnblogs.com/tianshidechibang234/p/4183600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!