react-native-camera-roll-picker icon indicating copy to clipboard operation
react-native-camera-roll-picker copied to clipboard

Permission Error on Android

Open alialaa opened this issue 8 years ago • 5 comments

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

alialaa avatar Apr 12 '17 11:04 alialaa

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

daose avatar Apr 15 '17 14:04 daose

Any update on this? I have the same problem even with
added to the AndroidManifest.xml

shushuy avatar Aug 08 '18 23:08 shushuy

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 avatar Aug 09 '18 08:08 rajnishcoder

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.

rajnishcoder avatar Aug 23 '18 05:08 rajnishcoder

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 ... /> }

oteinone avatar Jun 11 '19 13:06 oteinone