Tell us which versions you are using:
I should be able to open camera and/or cropper
Continually getting ambiguous error 'Error: Required permission missing' when attempting to call any ImagePicker methods
Follow android install steps as of Sept 29th 2020
Attempt to call ImagePicker.openCamera() or ImagePicker.openCropper()
3.
Receiving this error.
Error: Required permission missing
at Object.promiseMethodWrapper [as openCamera] (NativeModules.js:103)
at CollagePhotoFrame._this.cropPhoto (CollagePhotoFrame.js:18)
at onPress (CollagePhotoFrame.js:81)
at Pressability._performTransitionSideEffects (Pressability.js:697)
at Pressability._receiveSignal (Pressability.js:634)
at onResponderRelease (Pressability.js:530)
at Object.invokeGuardedCallbackImpl (ReactNativeRenderer-dev.js:265)
at invokeGuardedCallback (ReactNativeRenderer-dev.js:476)
at invokeGuardedCallbackAndCatchFirstError (ReactNativeRenderer-dev.js:500)
at executeDispatch (ReactNativeRenderer-dev.js:597)
I have the permissions set in AndroidManifest for CAMERA, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE
I've tried explicitly asking for permissions like so.
componentDidMount() {
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE)
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE)
PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA)
}
I've noticed WRITE_EXTERNAL_STORAGE always returns 'never_ask_again' no matter what the user does.
I've tried rolling back to '0.32.2' to no avail.
I've tried setting sdk target and compile version to 27 but that breaks other things in the app so I couldn't test.
I've also set android:requestLegacyExternalStorage="true" in AndroidManifest to no avail.
I've tried running on a simulator running android 10, a simulator running android 9, a OnePlus 7 running android 10.2, and a OnePlus 5 running android 10.
I've found out that if I go into the source to PickerModule.java and disable the permission check, the cropper appears to work correctly. My java skills are pretty much non existent so I can't say where the problem stems from.
PickerModule.java
@ReactMethod
public void openCropper(final ReadableMap options, final Promise promise) {
final Activity activity = getCurrentActivity();
if (activity == null) {
promise.reject(E_ACTIVITY_DOES_NOT_EXIST, "Activity doesn't exist");
return;
}
setConfiguration(options);
resultCollector.setup(promise, false);
final Uri uri = Uri.parse(options.getString("path"));
// permissionsCheck(activity, promise, Collections.singletonList(Manifest.permission.WRITE_EXTERNAL_STORAGE), new Callable<Void>() {
// @Override
// public Void call() {
startCropping(activity, uri);
// return null;
// }
// });
}
Android changed to only asking permissions the moment you need them. So you can't pre-ask a permission anymore at app start for example. So where it used to just ask for that permission, even though it did not need it, now the Android system suppresses the permissions request, and the check still throws. As long as you are supporting a minSdk version of 19, this appears to be safely removable.
WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />
seems to work for me
WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />seems to work for me
you just saved my day @initialsaet, not gonna lie! thanks!
@initialsaet Thank you so much! What a life saver!
I think this should be highlighted in the README. @initialsaet 's solution is working.
Most helpful comment
WRITE_EXTERNAL_STORAGE seems like it needs a wee bit more permission than normal.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />seems to work for me