react-native-image-crop-picker
react-native-image-crop-picker copied to clipboard
Getting "User did not grant library permission" on Android 11 even though permission is granted for Media and Files
Version
Tell us which versions you are using:
- react-native-image-crop-picker v0.36.0
- react-native v0.63.4
Platform
Tell us to which platform this issue is related
- Android compileSdkVersion = 29 buildToolsVersion = "29.0.2" targetSDKVersion = 29 minSDKVersion = 23
Expected behaviour
On using ImagePicker.open it should open the file chooser. This is how I'm using it:
ImagePicker.openPicker(imagePickerConfig)
.then(image => {
if (image) {
if (image.size > 10000000) {
WToast.show({
data:
"File size is too large to upload, choose 10 MB or below.",
duration: WToast.duration.SHORT,
position: WToast.position.TOP,
});
return;
}
if (image.path) {
this._uploadFile({ uri: image.path }, "IMAGE");
}
}
})
.catch(e => {
console.log("ImagePicker.open error: " + JSON.stringify(e));
if (e && e.code && e.code === "E_PICKER_CANCELLED") {
return;
}
Alert.alert(
"Photos gallery access denied",
"Please change your settings to allow cult.fit to access your photos gallery",
[
{ text: "Cancel" },
{
text: "Go to Settings",
onPress: () => OpenSettings.openSettings(),
},
],
{ cancelable: false }
);
});
Actual behaviour
It's going in the catch block and I'm getting this in console:
ImagePicker.open error: {"nativeStackAndroid":[],"userInfo":null,"message":"User did not grant library permission.","code":"E_NO_LIBRARY_PERMISSION"}
I've tried using android:requestLegacyExternalStorage="true" but it still doesn't work. I have WRITE_EXTERNAL_STORAGE in my manifest file already as well.
Steps to reproduce
- Use the code above to open image picker
Getting something similar:
{"nativeStackAndroid":[],"userInfo":null,"message":"**PathToFile**": open failed: EACCES (Permission denied)","code":"E_NO_IMAGE_DATA_FOUND"}
Getting this after I picked the image from the gallery using this lib.
Another note - I'm not sure but it seems to only happen in production app (when installed from Google Play)
I got that too. is react-native-image-crop-picker v0.36.2 fix this issue or not?
This package is not yet compatible with Android 11 which requires the use of scoped storage. Please see #1571
will there be any update for this package to support scoped storage soon? I was using this package in my app and i can't get it to work without legacyExternalStorage flag.
Getting the same error, any solution?
i think the package is not yet updated for the scoped storage policy in android 11
Ran into the same issue. According to release notes, v0.36.3 started Android 11 support. Upgrading to that version or higher fixed it for me.
Still occurring with:
react-native-image-crop-picker: 0.37.2
buildToolsVersion = "28.0.3"
minSdkVersion = 17
compileSdkVersion = 29
targetSdkVersion = 30
Still occurring with:
"react-native-image-crop-picker": "^0.37.2",
compileSdkVersion = 31
targetSdkVersion = 30
I used a patch file and problem is gone: https://github.com/ivpusic/react-native-image-crop-picker/issues/1571#issuecomment-1026636065
I took "user didnt grant library permisson" message in some devices while I had added this permisson
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
so I changed to
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.app.name">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" tools:replace="android:maxSdkVersion" />
and worked after change
Any update about this, it's still ocurring with 0.40.0 + react-native 0.72.4
Error code: E_NO_LIBRARY_PERMISSION
facing this issue If I do not use WRITE_EXTERNAL_STORAGE
Android 9
react-native-image-crop-picker": "0.40.2",
"react-native": "0.68.2"
@RodolfoGS Do we need to declare WRITE_EXTERNAL_STORAGE permission to make this library work in Android 12 and below?
Yes, add this line to your AndroidManifest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>