Search code examples
androidpermission-deniedandroid-10.0storage-access-framework

Lost access to DCIM/SUBDIR in Android 10


My application writes files to DCIM/SUBDIR like camera does. It was working fine before Android 10. Now it doesn't see the contents of this directory and produces

java.io.FileNotFoundException: /storage/emulated/0/DCIM/SUBDIR/myfile: open failed: EACCES (Permission denied)

How to overcome? I can't allow user to select file, because my workflow is like in camera: you are not selecting filename on each picture taken. So I probably can't use Storage Access Framework?


Solution

  • Try to add below key in <application> tag of AndroidManifest.xml

    <application android:requestLegacyExternalStorage="true"
    

    File access in Android 10 is based scoped storage standard.

    Please check this out

    This will work only for Android 10. It will not work if you set target version to 11. Check this.