use of com.facebook.react.ReactActivity in project react-native-image-picker by marcshilling.
the class ImagePickerModule method permissionsCheck.
private boolean permissionsCheck(@NonNull final Activity activity, @NonNull final Callback callback, @NonNull final int requestCode) {
final int writePermission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
final int cameraPermission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.CAMERA);
final boolean permissionsGrated = writePermission == PackageManager.PERMISSION_GRANTED && cameraPermission == PackageManager.PERMISSION_GRANTED;
if (!permissionsGrated) {
final Boolean dontAskAgain = ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) && ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.CAMERA);
if (dontAskAgain) {
final AlertDialog dialog = PermissionUtils.explainingDialog(this, options, new PermissionUtils.OnExplainingPermissionCallback() {
@Override
public void onCancel(WeakReference<ImagePickerModule> moduleInstance, DialogInterface dialogInterface) {
final ImagePickerModule module = moduleInstance.get();
if (module == null) {
return;
}
module.doOnCancel();
}
@Override
public void onReTry(WeakReference<ImagePickerModule> moduleInstance, DialogInterface dialogInterface) {
final ImagePickerModule module = moduleInstance.get();
if (module == null) {
return;
}
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
Uri uri = Uri.fromParts("package", module.getContext().getPackageName(), null);
intent.setData(uri);
final Activity innerActivity = module.getActivity();
if (innerActivity == null) {
return;
}
innerActivity.startActivityForResult(intent, 1);
}
});
dialog.show();
// responseHelper.invokeError(callback, "Permissions weren't granted");
return false;
} else {
String[] PERMISSIONS = { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA };
if (activity instanceof ReactActivity) {
((ReactActivity) activity).requestPermissions(PERMISSIONS, requestCode, listener);
} else if (activity instanceof OnImagePickerPermissionsCallback) {
((OnImagePickerPermissionsCallback) activity).setPermissionListener(listener);
ActivityCompat.requestPermissions(activity, PERMISSIONS, requestCode);
} else {
final String errorDescription = new StringBuilder(activity.getClass().getSimpleName()).append(" must implement ").append(OnImagePickerPermissionsCallback.class.getSimpleName()).toString();
throw new UnsupportedOperationException(errorDescription);
}
return false;
}
}
return true;
}
Aggregations