Android 权限问题

为什么80%的码农都做不了架构师?>>>   hot3.png

public boolean checkSelfPermission(String permission, int requestCode) {
    if (ContextCompat.checkSelfPermission(getActivity(), permission) != PackageManager.PERMISSION_GRANTED) {
        //如果没有权限,则申请
        ActivityCompat.requestPermissions(getActivity(), new String[]{permission}, requestCode);
        return false;
    }
    return true;
}

例:

if (checkSelfPermission(Manifest.permission.RECORD_AUDIO, PERMISSION_REQ_ID_RECORD_AUDIO)) {
    //如果有录音权限,则再检查摄像头权限,检查权限过程中,如果没有权限,会去申请
    checkSelfPermission(Manifest.permission.CAMERA, PERMISSION_REQ_ID_CAMERA);
}

 

转载于:https://my.oschina.net/tctw/blog/1498570

你可能感兴趣的:(Android 权限问题)