我有一个带有 9-patch 图像背景的小部件。 图像保存在/sdcard/mydir/bgs 中。
当我尝试使用 setImageViewUri 方法加载图像时,出现以下错误:
Unable to open content: file:///storage/emulated/0/sdcard/mydir/bgs
..
然后
...
open failed: EACCES (Permission denied)
这仅出现在主屏幕上,并且仅适用于 Nexus 10 和 Nexus 7(最新的启动器 4.4 不存在此错误)。我的应用程序上也有一些 RemoteView,并且一切正常。
我还在 list 中添加了 READ_EXTERNAL_STORAGE 或 WRITE_EXTERNAL_STORAGE。
我该如何解决?
更新:我检查了 setImageViewUri 方法,发现它改变了我的文件路径。
if (value != null) {
// Resolve any filesystem path before sending remotely
value = value.getCanonicalUri();
if (StrictMode.vmFileUriExposureEnabled()) {
value.checkFileUriExposed("RemoteViews.setUri()");
}
}
此方法接收我的值 (/sdcard/mydir/bgs) 并将其更改为 (storage/emulated/0/sdcard/mydir/bgs)。但是这个文件不存在通过 adb 进入系统。
最佳答案
与 Lollipop 一样,Google 引入了一种新方法,可以明确授予应用您希望它们在您的设备上使用的权限,并禁用您想要拒绝该应用的应用。如果您注意到,在您的 android 监视器中,日志会显示
java.io.FileNotFoundException: /storage/emulated/0/advert.mp4: open failed: EACCES (Permission denied)
EACCESS 权限被拒绝
是java 臭名昭著的FileNotFoundException
的原因。
要解决此问题,只需转到您的应用权限并为您的应用启用存储
关于Android - 无法打开内容 : file:///storage/emulated/0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20631446/