Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

READ/WRITE_EXTERNAL_STORAGE is declared but the app still cannot reach files

Erroropen failed: EACCES (Permission denied)

Short answer

On apps that target Android 11 or higher, WRITE_EXTERNAL_STORAGE has no effect on storage access, so declaring it cannot fix a failed write. Access now depends on what the file is: your own files need no permission, other apps' media need READ_MEDIA_* permissions, and other documents go through the system file picker.

  • Applies to Android 10 to 16, targetSdk 30 and higher, Android Studio current stable
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out which target level and Android version you are on, because the rules change at API 29 and API 30. Then note exactly which path or collection fails.

    grep -n "targetSdk\|compileSdk" app/build.gradle*
    adb shell getprop ro.build.version.sdk
  2. 2Match what you see, then jump to its fix

    1. 1Writes to a shared path fail even though the permission is grantedThe app targets Android 11 or higher and still relies on WRITE_EXTERNAL_STORAGEFix
    2. 2Your own photos load, but images from the gallery or other apps are missing from the queryYou read or change media that another app owns, without the right permissionFix
    3. 3Permission denied on a PDF, ZIP or file that another app saved in DownloadYou are opening another app's file in the Downloads collection or a non-media fileFix
    4. 4The failure happens only on Android 9 or lower, or after you opted out of scoped storageYour app is on Android 9 or lower, or has temporarily opted out of scoped storageFix

What does the error look like?

  • open failed: EACCES (Permission denied)
  • The permission dialog appears, but writing to /sdcard or Download still fails
  • WRITE_EXTERNAL_STORAGE is granted but has no effect

Cause 1 of 4

The app targets Android 11 or higher and still relies on WRITE_EXTERNAL_STORAGE

1Check

Look at your manifest and at the path you write to. For apps that target API 30 or higher, the write permission does not change what the app may access.

grep -rn "WRITE_EXTERNAL_STORAGE\|getExternalStorageDirectory" app/src

2Fix

Stop writing to arbitrary shared paths. Write into the app-specific folder on external storage (no permission needed on Android 4.4 and higher), or save media through MediaStore.

// Kotlin: app-specific external folder, no permission required
val dir = context.getExternalFilesDir(null)
val file = java.io.File(dir, "report.txt")
file.writeText("hello")

3Verify

Run the write on a device with Android 11 or higher and look for the file with Device File Explorer or adb.

adb shell ls /sdcard/Android/data/com.example.myapp/files

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 4

You read or change media that another app owns, without the right permission

1Check

On Android 10 and higher you need no storage permission for media your app created. Media created by other apps appears in MediaStore.Images, Video or Audio only when the matching permission is declared.

grep -n "READ_MEDIA\|READ_EXTERNAL_STORAGE" app/src/main/AndroidManifest.xml

2Fix

Declare only the media permissions you need, and ask for them at runtime. If you just need the user to pick files, use the photo picker instead of a permission.

<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
                 android:maxSdkVersion="29" />

3Verify

Rebuild, grant the dialog, and check that the other app's image shows up in your query.

# Accept the runtime dialog, then re-run the query

Confirmed by developer.android.com

Did this fix it?

Cause 3 of 4

You are opening another app's file in the Downloads collection or a non-media file

1Check

MediaStore does not hand out another app's Downloads files, and documents are not media at all. Check whether the failing file is a document or in Downloads.

adb shell ls -l /sdcard/Download

2Fix

Let the user pick the file with the Storage Access Framework (the system file picker). No storage permission is needed for that.

val picker = registerForActivityResult(
    androidx.activity.result.contract.ActivityResultContracts.OpenDocument()
) { uri -> /* read the file through contentResolver.openInputStream(uri) */ }
picker.launch(arrayOf("application/pdf"))

3Verify

Pick the file in the system dialog and read its first bytes.

adb logcat -s MyApp

Confirmed by developer.android.com

Did this fix it?

Cause 4 of 4

Your app is on Android 9 or lower, or has temporarily opted out of scoped storage

1Check

On these setups the old rules apply: you must request READ_EXTERNAL_STORAGE to read any media file, and WRITE_EXTERNAL_STORAGE to change them.

adb shell getprop ro.build.version.sdk

2Fix

Keep both permissions in the manifest for those devices, request them at runtime, and plan the move to scoped storage.

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

3Verify

Accept the runtime prompt on the old device and repeat the read.

# Accept the runtime prompt, then repeat the read

Confirmed by developer.android.com

Did this fix it?

How do I stop it coming back?

  • Store app-only data in app-specific directories so no permission is ever needed.
  • Use the photo picker or the system file picker when the user chooses the file.
  • Test on one device at API 29 and one at API 34 or newer, not only on your main phone.
  • Add maxSdkVersion="29" to WRITE_EXTERNAL_STORAGE, as the Android docs show, so newer versions ignore it.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Mobile apps

adb tcpip 5555 fails because no device is found

adb: more than one device/emulator

adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.