解决java.io.FileNotFoundException: open failed: EACCES (Permission denied)异常
使用Glide显示本地图片,结果报如下异常:
java.io.FileNotFoundException: open failed: EACCES (Permission denied) at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:315) at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:220) at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1561) at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1478) at com.bumptech.glide.load.data.AssetFileDescriptorLocalUriFetcher.loadResource(AssetFileDescriptorLocalUriFetcher.java:20) at com.bumptech.glide.load.data.AssetFileDescriptorLocalUriFetcher.loadResource(AssetFileDescriptorLocalUriFetcher.java:11) at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:44) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100) at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:95) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:88) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311) at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:412) at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailedInternal(SourceGenerator.java:222) at com.bumptech.glide.load.engine.SourceGenerator$1.onLoadFailed(SourceGenerator.java:108) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:167) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154) at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:50) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100) at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:95) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:88) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311) at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherFailed(DecodeJob.java:412) at com.bumptech.glide.load.engine.SourceGenerator.onLoadFailedInternal(SourceGenerator.java:222) at com.bumptech.glide.load.engine.SourceGenerator$1.onLoadFailed(SourceGenerator.java:108) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.startNextOrFail(MultiModelLoader.java:167) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.onLoadFailed(MultiModelLoader.java:154) at com.bumptech.glide.load.data.LocalUriFetcher.loadData(LocalUriFetcher.java:50) at com.bumptech.glide.load.model.MultiModelLoader$MultiFetcher.loadData(MultiModelLoader.java:100) at com.bumptech.glide.load.engine.SourceGenerator.startNextLoad(SourceGenerator.java:95) at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:88) at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:311) at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:280) at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:235) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:413) at java.lang.Thread.run(Thread.java:919) at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultPriorityThreadFactory$1.run(GlideExecutor.java:372) 2022-08-10 23:14:35.988 6659-6873/com.zcgw.group.app W/libEGL: EGLNativeWindowType 0x7829a4b990 disconnect failed --------- beginning of system 2022-08-10 23:15:55.008 6659-6873/com.zcgw.group.app W/libEGL: EGLNativeWindowType 0x77b7cd9b10 disconnect failed 2022-08-10 23:16:00.127 6659-6701/com.zcgw.group.app W/System: A resource failed to call close.
查看AndroidManifest.xml文件,也是有如下权限:
<!-- 写数据权限 --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <!-- 读取数据权限 --> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
也进行了动态权限申请,图片文件也确实是存在的,但还是报FileNotFoundException异常。猜测是Android 10的问题。后来查询才发现,Android 10需要在AndroidManifest.xml文件的application节点添加android:requestLegacyExternalStorage=”true”,如下代码:
<application android:name=".GroupApp" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:requestLegacyExternalStorage="true" android:theme="@style/Theme.GroupApp"/>
亲测可用!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。