android10 Glide加载本地图片不显示的问题解决

Glide版本:

'com.github.bumptech.glide:glide:4.11.0'

加载图片的代码

Glide.with(this)
     .load(imgLocalPath)
     .into(imageView);

在使用的过程中,因为模拟器的问题一直使用Android8.0版本,手机又是9.0版本,项目sdk配置如下

compileSdkVersion 30
buildToolsVersion "30.0.0"
defaultConfig {
    applicationId "com.example.myapplication"
    minSdkVersion 26
    targetSdkVersion 30
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

选择相册中的图片后在android10上一直显示不出来,权限也都给了

发现manifest少了句配置

android:requestLegacyExternalStorage="true"

加在<application>标签下

也可以把targetSdkVersion改为28及以下,但是不建议

原因是Android 10文件存储机制修改成了沙盒模式,APP只能访问自己目录下的文件和公共媒体文件Android10以下,还是使用旧的文件存储方式,Android 10即使获取读取权限,访问外部存储也受到了限制。

感谢https://www.jianshu.com/p/ba6419bc9059

猜你喜欢

转载自blog.csdn.net/qq_40516592/article/details/110847929