3

我开始着手将 SDK 迁移到 29。

我遇到的主要问题Environment.getExternalStorageDirectory()是已弃用和限定存储。

我把它全部替换为Context# getExternalFilesDir(null). 它开始使用 Android 11 beta 开发 Pixel 3a。

但是当我在带有 Android 10 的三星 s9+ 上对其进行测试时。它开始给我这个错误:

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)

我试图在Glide的帮助下加载图像。

我也在其他设备上进行了测试。它不仅适用于 Android 10 设备。它适用于运行 Android 9 及更低版本和 Android 11 Beta 的设备。

然后,我将它放在android:requestLegacyExternalStorage = "true"我的清单中,它也开始在 Android 10 上运行。

现在我的问题是:

  • 如果它与 Scoped 存储有关,那么为什么它可以在 Android 11 而不是 Android 10 上运行?
  • 我们是否只需要 Android 10 的旧标志来完成这项工作?
4

0 回答 0