react-native-cameraroll: Getting permission denied error on Android after I have inlcuded permissions in AndroidManifest.xml

I have already included the following permissions in my AndroidManifest.xml:

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

However after I call CameraRoll.saveToCameraRoll(Platform.OS === 'ios' ? this.props.imageItem.url : this.state.imageUri); I’m still getting the following permission error:


03-28 15:50:22.567 13354 13395 W ReactNativeJS: Possible Unhandled Promise Rejection (id: 0):
03-28 15:50:22.567 13354 13395 W ReactNativeJS: Error: Permission denied
03-28 15:50:22.567 13354 13395 W ReactNativeJS: createErrorFromErrorData@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2012:26
03-28 15:50:22.567 13354 13395 W ReactNativeJS: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:1964:51
03-28 15:50:22.567 13354 13395 W ReactNativeJS: __invokeCallback@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2531:23
03-28 15:50:22.567 13354 13395 W ReactNativeJS: http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2262:34
03-28 15:50:22.567 13354 13395 W ReactNativeJS: __guard@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2435:15
03-28 15:50:22.567 13354 13395 W ReactNativeJS: invokeCallbackAndReturnFlushedQueue@http://10.0.2.2:8081/index.delta?platform=android&dev=true&minify=false:2261:21
03-28 15:50:22.567 13354 13395 W ReactNativeJS: invokeCallbackAndReturnFlushedQueue@[native code]

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (3 by maintainers)

Most upvoted comments

@ethanyuwang the thing is that you have to explicitly ask for the permission. Adding them to the manifest is just a way to list all the permission you’re going to be asking inside the app.

You can solve this easily with something like this:

import { PermissionsAndroid, Platform } from 'react-native';
import CameraRoll from '@react-native-community/cameraroll';

const checkAndroidPermission = async () => {
    try {
      const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE;
      await PermissionsAndroid.request(permission);
      Promise.resolve();
    } catch (error) {
      Promise.reject(error);
    }
};

const savePicture = async () => {
    if (Platform.OS === 'android'){
      await checkAndroidPermission();
    }
   CameraRoll.saveToCameraRoll(tag, [type]);
};

Hope it helps 😸

@dmevt this fixed the problem for me, thanks!

I have the same issue. I am using react-native-view-shot and @react-native-community/cameraroll to capture the screenshot and save it on the external storage. But I always get the permission denied error in Android. I have tried all the method above, but the same. I have checked the permission status with PermissionAndroid and it said ‘granted’. But I can’t save the screenshot with the error: ‘Permission denied’. Which permissions are more needed? Please help me. Android version is 29.

Can we have this on the documentation?

@joseguerrerov will like to know if the permission function will be required for ios. Also when I followed your procedure for android… I get something like this in return content://media/external_primary/file/92336 And I cannot see the image in the android gallery … will like to know if there is any other thing to do.

downloaded new version now it is working properly

Hi @souljacker, Did you put that permission in the Manifest? <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

It would be a good idea to add that snippet to the readme or probably to the code itself @bartolkaruza WDYT?

Yeah, after doing what is described here it worked. It would be nice to have this on the docs, though.

@joseguerrerov will like to know if the permission function will be required for ios. Also when I followed your procedure for android… I get something like this in return content://media/external_primary/file/92336 And I cannot see the image in the android gallery … will like to know if there is any other thing to do.