react-native-image-picker: Permission error

Bug

In android, image picker asks permission even though it was granted before. And after granted, image picker does not show anything with console error " Permissions weren’t granted". Tried in android 10 emulator.

Environment info

React native info output:

 // paste it here

Library version: x.x.x

Steps To Reproduce

  1. Ask permission before running image picker
  2. Run image picker.
  3. It asks permission again, and even allowed, it errors out that “no permission granted” …

Describe what you expected to happen:

  1. Do not ask permission, if it is already granted

Reproducible sample code

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 27 (4 by maintainers)

Most upvoted comments

This should be open. As we know Android 11 is getting a new permission with a different way to access the files. Is there any update for this? https://support.google.com/googleplay/android-developer/answer/10467955

FIXED ISSUE ON ANDROID 10 DEVICE exact response: error: "/storage/emulated/0/DCIM/Camera/IMG_849.jpg: open failed: EACCES (Permission denied)"

I’ve permission keys in Manifest file <uses-permission android:name="android.permission.CAMERA" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

FIX Add this permission in your manifest file inside <application /> tag android:requestLegacyExternalStorage="true"

https://github.com/react-native-community/react-native-image-picker/issues/1233#issuecomment-561349254

@kumold Checkout your AndroidManifest.xml and see if it has these lines of code:

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

我以某种方式完成了上述所有操作(添加了android:requestLegacyExternalStorage =“ true”),并添加了所有必需的权限,但是我的应用仍然无法访问设备上的图片。还有其他人遇到过同样的事情吗?随附了我的AndroidManifest.xml文件的图片。 图片

如果您使用的不是真实设备,请尝试使用真实设备。并在运行前清除缓存。如果仍然遇到问题,请向我发送您正在使用的代码和Android版本。

+1

From the docs

Image/video captured via camera will be stored in temporary folder so will be deleted any time, so don’t expect it to persist. Use saveToPhotos: true (default is false) to save the file in the public photos. saveToPhotos requires WRITE_EXTERNAL_STORAGE permission on Android 28 and below (You have to obtain the permission, the library does not).

So you have to obtain WRITE_EXTERNAL_STORAGE using built in react-native permissions or some third party library

You could try following:

<!-- AndroidManifest.xml -->

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" />
// JavaScrip

 if (isAndroid) {
     const isGranted = await PermissionsAndroid.check(PermissionsAndroid.PERMISSIONS.CAMERA);

     if (isGranted) launchCamera(opts, handler);
     else {
         const granted = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);

          if (granted === PermissionsAndroid.RESULTS.GRANTED) launchCamera(opts, handler);
          else openAlert();
     } 
} else {
  // iOS
  launchCamera(opts, handler);
}

It works, but yesterday i got some bugs from production Android 10 devices - user not granted access to photos, even though app pops up alert which asks user to grant it, but either way grant or not i still do not have access to photos. Meybe for older Android we still need android:requestLegacyExternalStorage=“true” property. Could you please tell me what devices you use for develpment (model and system version)?

Could you also tell me what is set in your gradle.build for the following:

 buildToolsVersion = "30.0.2"
 minSdkVersion = 21
 compileSdkVersion = 30
 targetSdkVersion = 30
  • Version 2.x.x is not longer supported, please upgrade to 3.x.x. Version 3.x.x no longer requires any permission as it is on android. Read the docs carefully.

Alright, even if it’s just moving the problem somewhere else, if I want to use image-picker correctly, I’ll still have to use requestLegacyExternalStorage…

  • Version 2.x.x is not longer supported, please upgrade to 3.x.x. Version 3.x.x no longer requires any permission as it is on android. Read the docs carefully.

I tried adding the requestLegacyExternalStorage thing in every way i can think of, but i didn’t work.


<uses-permission android:name="android:requestLegacyExternalStorage="true""/>  doesn't build
<uses-permission android:name="android:requestLegacyExternalStorage='true'"/>  doesn't work
<uses-permission android:name="android:requestLegacyExternalStorage"/>  doesn't work
<uses-permission android:name="android:requestLegacyExternalStorage=true"/> doesn't work

Can anyone help me figure it out?

Add it to <application> tag

hello, I am also facing the same problem. When i add camera permission in AndroidManifest file i get the following error

This library does not require Manifest.permission.CAMERA, if you add this permission in manifest then you have to obtain the same.

i have added the following permissions

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

and i have also tried adding android:requestLegacyExternalStorage="true" inside <application /> when i remove <uses-permission android:name="android.permission.CAMERA"/> i get {" errorCode" : "permission"} i want to take the picture and save it on the public storage on my device. so i have added saveToPhotos:true, in the options. but when i remove this ‘saveToPhoto:true’ the camera works but according to the documentation that image is stored in the temporary storage and will be removed anytime.

do anyone have the solution to the this problem ? my version is "react-native-image-picker": "^4.3.0",

Note: I am getting this error on the physical device during development. i am not using virtual device. Thankyou.