Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission error #1259

Closed
kumold opened this issue Dec 25, 2019 · 27 comments
Closed

Permission error #1259

kumold opened this issue Dec 25, 2019 · 27 comments
Labels
stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@kumold
Copy link

kumold commented Dec 25, 2019

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

@zeabdelkhalek
Copy link

@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"/>

@deepankarsandy
Copy link

deepankarsandy commented Jan 9, 2020

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 tag
android:requestLegacyExternalStorage="true"

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

@stale
Copy link

stale bot commented Mar 9, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open.

@stale stale bot added the stale There has been a lack of activity on this issue and it may be closed soon. label Mar 9, 2020
@stale
Copy link

stale bot commented Mar 16, 2020

Closing this issue after a prolonged period of inactivity. Fell free to reopen this issue, if this still affecting you.

@stale stale bot closed this as completed Mar 16, 2020
@samuelj1323
Copy link

Adding the android:requestLegacyExternalStorage="true" works, I took a wild guess and put it in the part of the AndroidManifest.xml file. It works just fine. The Node.js terminal gives me a lot of text, but it seems to be working.

@lucaspdude
Copy link

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?

@negrudev
Copy link

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

@papidb
Copy link

papidb commented Sep 5, 2020

@omeshkumarfso
Copy link

Add these both permission of read and write, to solve this issue

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

Add this below line in Application tag
android:requestLegacyExternalStorage="true"

@beauhsia
Copy link

Somehow I did everything described above (added the android:requestLegacyExternalStorage="true"), and added all of the required permissions, but my app still can't access my images on my device. Are there any other person experiencing the same thing? The picture of my AndroidManifest.xml file is attached.
image

@gopikrishnagurram
Copy link

gopikrishnagurram commented Dec 5, 2020

<uses-permission android:name="android.permission.INTERNET" />
<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"/>

Added android:requestLegacyExternalStorage="true" to the application tag, still facing same issue. Please help me if anyone knows howto fix

@SohaibKtb
Copy link

still the same error: {"errorCode": "permission"}

manifest:

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

    <!-- Include this only if you are planning to use the microphone for video recording -->
    <uses-permission android:name="android.permission.RECORD_AUDIO"/>

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

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

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:allowBackup="false"
      android:theme="@style/AppTheme"
      android:requestLegacyExternalStorage="true">

package.json:

    "react": "16.13.1",
    "react-native": "0.63.3",
    "react-native-image-picker": "^3.0.0",

the error occures when I am calling this function:

launchCamera(options, (e) => { console.log(e)

any solution?

@ravirajn22
Copy link
Contributor

What options are you using?

@SohaibKtb
Copy link

@ravirajn22
these are the options:

let options = {
                includeBase64: true,
                quality: 0.5,
                videoQuality: 'high',
                mediaType: 'photo',
                saveToPhotos: true
            };

@ravirajn22
Copy link
Contributor

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

@SohaibKtb
Copy link

@ravirajn22 Thank you, I got it.

@omeshkumarfso
Copy link

Somehow I did everything described above (added the android:requestLegacyExternalStorage="true"), and added all of the required permissions, but my app still can't access my images on my device. Are there any other person experiencing the same thing? The picture of my AndroidManifest.xml file is attached.
image

if you are not using real device then try on real device. And clear cache before running. if still face problem send me the code and android version which you are using.

@caoruonan
Copy link

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

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

+1

@AugustoAleGon
Copy link

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

@minhchienwikipedia
Copy link

Any update about new permission for Android 11?

@MayoudP
Copy link

MayoudP commented Apr 27, 2021

Nothing new ? Discussion also open here : #1672

@ravirajn22
Copy link
Contributor

  • 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.

@MayoudP
Copy link

MayoudP commented Apr 28, 2021

  • 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...

@ravirajn22
Copy link
Contributor

@MayoudP no

@Sayanc2000
Copy link

Is there any way to solve this problem on an expo app, because the android manifest file isn't available in expo environment

@cybergears
Copy link

cybergears commented Nov 21, 2021

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.

@kristijantomic
Copy link

kristijantomic commented Nov 21, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests