ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.09k stars 1.55k forks source link

Getting "User did not grant library permission" on Android 11 even though permission is granted for Media and Files #1588

Open ayusch-apps-curefit opened 3 years ago

ayusch-apps-curefit commented 3 years ago

Version

Tell us which versions you are using:

Platform

Tell us to which platform this issue is related

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

  1. Use the code above to open image picker
nadav2051 commented 3 years ago

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)

Seu07 commented 3 years ago

I got that too. is react-native-image-crop-picker v0.36.2 fix this issue or not?

mysport12 commented 3 years ago

This package is not yet compatible with Android 11 which requires the use of scoped storage. Please see #1571

melbin97 commented 3 years ago

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.

ghasemikasra39 commented 3 years ago

Getting the same error, any solution?

melbin97 commented 3 years ago

i think the package is not yet updated for the scoped storage policy in android 11

bernardmma commented 2 years ago

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.

CapitanRedBeard commented 2 years ago

Still occurring with:

react-native-image-crop-picker: 0.37.2
buildToolsVersion = "28.0.3"
minSdkVersion = 17
compileSdkVersion = 29
targetSdkVersion = 30
ghost commented 2 years ago

Still occurring with:

"react-native-image-crop-picker": "^0.37.2",

compileSdkVersion = 31
targetSdkVersion = 30
retyui commented 2 years ago

I used a patch file and problem is gone: https://github.com/ivpusic/react-native-image-crop-picker/issues/1571#issuecomment-1026636065

amirbhz86 commented 1 year ago

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

RodolfoGS commented 1 year ago

Any update about this, it's still ocurring with 0.40.0 + react-native 0.72.4 Error code: E_NO_LIBRARY_PERMISSION

Yandamuri commented 8 months ago

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?

RodolfoGS commented 8 months ago

Yes, add this line to your AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>