react-native-image-crop-picker icon indicating copy to clipboard operation
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

Open ayusch-apps-curefit opened this issue 4 years ago • 15 comments

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

  1. Use the code above to open image picker

ayusch-apps-curefit avatar May 17 '21 10:05 ayusch-apps-curefit

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)

nadav2051 avatar May 17 '21 11:05 nadav2051

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

Seu07 avatar May 17 '21 11:05 Seu07

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

mysport12 avatar May 26 '21 19:05 mysport12

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.

melbin97 avatar Jun 14 '21 10:06 melbin97

Getting the same error, any solution?

ghasemikasra39 avatar Jun 30 '21 07:06 ghasemikasra39

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

melbin97 avatar Jun 30 '21 08:06 melbin97

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.

bernardmma avatar Dec 25 '21 01:12 bernardmma

Still occurring with:

react-native-image-crop-picker: 0.37.2
buildToolsVersion = "28.0.3"
minSdkVersion = 17
compileSdkVersion = 29
targetSdkVersion = 30

CapitanRedBeard avatar Jan 24 '22 22:01 CapitanRedBeard

Still occurring with:

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

compileSdkVersion = 31
targetSdkVersion = 30

ghost avatar Jan 31 '22 13:01 ghost

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

retyui avatar Feb 01 '22 09:02 retyui

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

amirbhz86 avatar Nov 05 '22 14:11 amirbhz86

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

RodolfoGS avatar Sep 13 '23 19:09 RodolfoGS

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?

Yandamuri avatar Jan 03 '24 11:01 Yandamuri

Yes, add this line to your AndroidManifest.xml

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

RodolfoGS avatar Jan 14 '24 13:01 RodolfoGS