jeanpan / react-native-camera-roll-picker

📷 A React Native component providing images selection from camera roll
https://www.npmjs.com/package/react-native-camera-roll-picker
MIT License
422 stars 176 forks source link

Permission Error on Android #39

Open alialaa opened 7 years ago

alialaa commented 7 years ago

Hello, I get this error on android and I can't find a way to set these permissions, any idea?

Error: Could not get photos: need READ_EXTERNAL_STORAGE permission

daose commented 7 years ago

You'll want to edit your AndroidManifest.xml to include that permission (usually located ./android/app/src/main/AndroidManifest.xml)

Add the line:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
shushuy commented 6 years ago

Any update on this? I have the same problem even with

added to the AndroidManifest.xml

rajnishcoder commented 6 years ago

Same problem and I'm working on latest React native version 0.55.2 and I don't have any android or iOS folder

rajnishcoder commented 6 years ago

agreed with @daose and if you are newly setup your project and cannot able to find android folder so run react-native eject read more to eject iOS and android app from react app.

and make sure you added CAMERA permission too like this:-

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

in your /android/app/src/main/AndroidManifest.xml file.

oteinone commented 5 years ago

If anyone else stumbles here, here's a short explanation:

Currently Android requires you to request these permissions separately on the go. Having uses-permission in manifest is not enough. The camera roll picker component has not updated to include this feature.

I managed to get the component working without any problems by asking the permission myself in the component using camera roll component. I added "rollPermissionExists" to the parent component's state and only show the camera roll component if rollPermissionExists is true

Here's a few code snippets to help anyone struggling with this (also remember to add rollPermissionExists and default value to your state).

Add PermissionsAndroid to your component

import { PermissionsAndroid } from 'react-native';

Call this method when you are about to show the camera roll component

// The 
async requestExternalStorageAccess() {
    try {
        const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
        );
        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            this.setState({ rollPermissionExists: true })
        } else {
            this.setState({ rollPermissionExists: false })
        }
        } catch (err) {
        console.warn(err);
        }
}

Only show the picker if rollPermissionExists is true in render()

{ this.state.rollPermissionExists && <CameraRollPicker ... /> }