Behavioural change in scoped storage on Android 10

Viewed 792

I started working on the SDK migration to 29.

The main issue that I had with this was that the Environment.getExternalStorageDirectory() was deprecated and scoped storage.

I had it all replaced with Context# getExternalFilesDir(null). It started working on Pixel 3a with Android 11 beta.

But when I tested it on Samsung s9+ with Android 10. It started giving me this error:

W/Glide: Load failed for /storage/emulated/0/Pictures/UHD Wallpapers/_uhdarchitecture208.jpg with size [96x96]
    class com.bumptech.glide.load.engine.GlideException: Failed to load resource
    There were 3 causes:
    java.io.FileNotFoundException(/storage/emulated/0/Pictures/UHD Wallpapers/_uhdarchitecture208.jpg: open failed: EACCES (Permission denied))
    java.io.FileNotFoundException(/storage/emulated/0/Pictures/UHD Wallpapers/_uhdarchitecture208.jpg: open failed: EACCES (Permission denied))
    java.io.FileNotFoundException(open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
      Cause (1 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.nio.ByteBuffer, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(/storage/emulated/0/Pictures/UHD Wallpapers/_uhdarchitecture208.jpg: open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class java.io.FileNotFoundException: /storage/emulated/0/Pictures/UHD Wallpapers/_uhdarchitecture208.jpg: open failed: EACCES (Permission denied)
      Cause (2 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class java.io.InputStream, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(/storage/emulated/0/Pictures/UHD Wallpapers/_uhdarchitecture208.jpg: open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class java.io.FileNotFoundException: /storage/emulated/0/Pictures/UHD Wallpapers/_uhdarchitecture208.jpg: open failed: EACCES (Permission denied)
      Cause (3 of 3): class com.bumptech.glide.load.engine.GlideException: Fetching data failed, class android.os.ParcelFileDescriptor, LOCAL
    There was 1 cause:
    java.io.FileNotFoundException(open failed: EACCES (Permission denied))
     call GlideException#logRootCauses(String) for more detail
        Cause (1 of 1): class java.io.FileNotFoundException: open failed: EACCES (Permission denied)

I was trying to load an image with the help of Glide.

I tested it on other devices as well. It's NOT working only on Android 10 devices. It's working on devices with Android 9 and below and Android 11 Beta.

Then, I placed the android:requestLegacyExternalStorage = "true" in my manifest and it started working on Android 10 as well.

Now my questions are:

  • If it is related to Scoped storage than why is it working on Android 11 and not Android 10?
  • Do we only need the legacy flag for Android 10 to make this work?
0 Answers
Related