1、单个权限检查及申请

        

private void checkSinglePermission(){
        // 在需要的地方,如Activity中
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_PHONE_STATE)
                != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_PHONE_STATE},
                    1001);
        }
    }

2、多个权限检查及申请

        

private String[] mPermissions = new String[] {
            Manifest.permission.CAMERA,
            Manifest.permission.ACCESS_FINE_LOCATION
};
private boolean checkMorePermission(){
        for (String permission : mPermissions) {
            if (ContextCompat.checkSelfPermission(this, permission) !=             
                   PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部