android动态申请拍照获取照片权限

拍照并获取照片需要的是拍照和读写sd卡权限

@Override
public void clickCamera() {
    Log.d("roamer", "clickCamera");
 
    if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA)) {
          拍照方法
    } else {
        //提示用户开户权限   拍照和读写sd卡权限
        String[] perms = {Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
        ActivityCompat.requestPermissions(this, perms, RESULT_CODE_STARTCAMERA);
    }
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
                                       @NonNull int[] grantResults) {
switch (requestCode) {
 case RESULT_CODE_STARTCAMERA: {
            boolean cameraAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED;
            if (cameraAccepted) {
              调用拍照方法
            } else {
                //用户授权拒绝之后,友情提示一下就可以了
                ToastUtils.show(ChatActivity.this, "请开启应用拍照权限");
            }
        }
        break;
        default:
    }
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}


你可能感兴趣的:(android)