react-native-image-crop-picker
react-native-image-crop-picker copied to clipboard
Android permissions error: Required permission missing
Version
Tell us which versions you are using:
- react-native-image-crop-picker v0.35.0
- react-native v0.63.2
- gradle stuff buildToolsVersion = "29.0.3" ext.kotlin_version = '1.3.21' minSdkVersion = 19 compileSdkVersion = 29 targetSdkVersion = 29
Platform
- Android only (iOS works correctly)
Expected behaviour
I should be able to open camera and/or cropper
Actual behaviour
Continually getting ambiguous error 'Error: Required permission missing' when attempting to call any ImagePicker methods
Steps to reproduce
-
Follow android install steps as of Sept 29th 2020
-
Attempt to call ImagePicker.openCamera() or ImagePicker.openCropper()
Attachments
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.
WRITE_EXTERNAL_STORAGE似乎需要比通常更多的权限。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />
似乎为我工作
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
tools:node="replace" I can't compile it and I have to delete it
My issue was that I wasn't being able to use the crop-picker inside the emulator, Pixel XL API 13. After adding a log entry on PickerModule::permissionsCheck I was able to see the missing permission was READ_MEDIA_IMAGES.
Log.d("picker", "Missing Permissions " + missingPermissions);
01-14 21:57:09.254 19135 19200 D picker : Missing Permissions [android.permission.READ_MEDIA_IMAGES]
Adding the permission to AndroidManifest fixed the problem. Now I get a prompt to allow access and it the crop picker works after granting it.
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
My issue was that I wasn't being able to use the crop-picker inside the emulator, Pixel XL API 13. After adding a log entry on PickerModule::permissionsCheck I was able to see the missing permission was READ_MEDIA_IMAGES.
Log.d("picker", "Missing Permissions " + missingPermissions); 01-14 21:57:09.254 19135 19200 D picker : Missing Permissions [android.permission.READ_MEDIA_IMAGES]
Adding the permission to AndroidManifest fixed the problem. Now I get a prompt to allow access and it the crop picker works after granting it.
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
This worked for me. I'm using api33, and after this, my image-crop-picker package is working fine.
Step 1: Install package react native permissions
Step 2: Add the below code in the AndroidManifest.xml file:
Step 3: Add the line inside AndroidManifest.xml and add in the application section:
android:requestLegacyExternalStorage="true"
Step 4: Add inside index.js file:
PERMISSIONS.ANDROID.CAMERA;
I had some similar problem. I was using a resizable emulator device on Android Studio w/ API 33. Tbh though, I don't think that matters because I deleted my react-native-image-crop-picker dependency and reinstalled it--that fixed it.
You're a GOD my man!!! Saved my life xD
My issue was that I wasn't being able to use the crop-picker inside the emulator, Pixel XL API 13. After adding a log entry on PickerModule::permissionsCheck I was able to see the missing permission was READ_MEDIA_IMAGES.
Log.d("picker", "Missing Permissions " + missingPermissions); 01-14 21:57:09.254 19135 19200 D picker : Missing Permissions [android.permission.READ_MEDIA_IMAGES]
Adding the permission to AndroidManifest fixed the problem. Now I get a prompt to allow access and it the crop picker works after granting it.
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
Is there a way I can add this permission using Expo?