1.액티비티 자체에서 권한을 요청한다.
permissionsNeeded에 들어갈 String배열은 이미 Manifes.permission.READ_EXTERNAL_STORAGE같이
정해졌다.
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.CAMERA
ArrayList<String> permissionsNeeded = new ArrayList<>();
ActivityCompat.requestPermissions(activity,
permissionsNeeded.toArray(new String[permissionsNeeded.size()]),
requestCode);
2. 권한 요청된 값이 돌아온다.
requestCode는 미리 약속된 값들이다.
@Override
public void onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case CAMERA_PERMISSIONS_REQUEST:
if (PermissionUtils.permissionGranted(requestCode, CAMERA_PERMISSIONS_REQUEST, grantResults)) {
startCamera();
}
break;
}
}