react-native-fs: ENOENT: open failed: EACCES (Permission denied), open '/storage/emulated/0/Download/

I encountered this issue so I am writing this just to tell everyone how to fix this permission issue in android

I have added permissions in manifest file

....
 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> // worked without this also
...
<application ...
android:requestLegacyExternalStorage="true" // this is needed
....
>

Also don’t forget to ask for permission

try {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
      {
        title: "Cool Photo App Camera Permission",
        message:
          "Your app needs permission.",
        buttonNeutral: "Ask Me Later",
        buttonNegative: "Cancel",
        buttonPositive: "OK"
      }
    );
    if (granted === PermissionsAndroid.RESULTS.GRANTED) {
      return true;
    } else {
      console.log("Camera permission denied");
      return false;
    }
  } catch (err) {
    console.warn(err);
    return false;
  }

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 51
  • Comments: 22

Most upvoted comments

<application … android:requestLegacyExternalStorage=“true” … I make this change but still issue is there it gives me error like ENOENT: open failed: EACCES (Permission denied), open ‘/storage/emulated/0/Download/config.txt’

android:requestLegacyExternalStorage=“true” not working api level 30

<application … android:requestLegacyExternalStorage=“true” // this is needed …

work for me

android\app\build\intermediates\merged_manifests\debug\arm64-v8a\AndroidManifest.xml:27: AAPT: error: attribute android:requestLegacyExternalStorage not found.

has error

thanks worked for me as well. just do not forget to rebuild the app.

For expo you can use this plugin i wrote to add the tag to <application> in a managed workflow.

app.json

"plugins": ["./expo/with-legacy-storage.js"]

./expo/with-legacy-storage.js

const { withAndroidManifest } = require('@expo/config-plugins')

module.exports = (config) => {
	const modifyAndroidManifest = (manifest) => {
		const applicationTag = manifest['application'][0]
		applicationTag.$['android:requestLegacyExternalStorage'] = 'true'
		manifest['application'][0] = applicationTag
		return manifest
	}
	return withAndroidManifest(config, async (config) => {
		config.modResults.manifest = modifyAndroidManifest(
			config.modResults.manifest,
		)

		return config
	})
}

<application ...
android:requestLegacyExternalStorage="true"

Add this and rebuild the app

<application … android:requestLegacyExternalStorage=“true” … I make this change but still issue is there it gives me error like ENOENT: open failed: EACCES (Permission denied), open ‘/storage/emulated/0/Download/config.xlsx’

<application … android:requestLegacyExternalStorage=“true” // this is needed …

work for me

It solved when restarted the app