我正在尝试在Android 4.2锁定屏幕上的应用中启用我的小部件并且它工作正常,但它无法解析任何图像uris。我得到的错误是:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/com.tvshowfavs/cache/22kifo7sdmyet7x7kphdgch69: open failed: EACCES (Permission denied)
at libcore.io.IoBridge.open(IoBridge.java:416)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at java.io.FileInputStream.<init>(FileInputStream.java:105)
at android.content.ContentResolver.openInputStream(ContentResolver.java:447)
at android.widget.ImageView.resolveUri(ImageView.java:636)
at android.widget.ImageView.setImageURI(ImageView.java:381)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.widget.RemoteViews$ReflectionAction.apply(RemoteViews.java:1146)
at android.widget.RemoteViews.performApply(RemoteViews.java:2304)
at android.widget.RemoteViews.apply(RemoteViews.java:2263)
at android.widget.RemoteViewsAdapter$RemoteViewsFrameLayout.onRemoteViewsLoaded(RemoteViewsAdapter.java:286)
at android.widget.RemoteViewsAdapter$RemoteViewsFrameLayoutRefSet.notifyOnRemoteViewsLoaded(RemoteViewsAdapter.java:335)
at android.widget.RemoteViewsAdapter$4.run(RemoteViewsAdapter.java:993)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.os.HandlerThread.run(HandlerThread.java:60)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:400)
任何人都知道为什么它无法打开存储在模拟存储中的图像?此图像以前是使用Environment.getExternalStorageDirectory()下载和缓存的,因此应将其正确写入存储目录。这是在Nexus 10上,我在尝试加载任何图像时收到此异常。任何帮助表示赞赏。
答案 0 :(得分:0)
好吧,我发现了问题。我使用的是RemoteView方法setImageUri(),它看起来好像不起作用,因为不同的进程无法访问该文件。解决方案是使用setImageViewBitmap()并自己解码位图,例如:BitmapFactory.decodeFile(Uri.parse(uri).getPath())
我觉得奇怪的是setImageUri()可以正常使用启动器,但不能在锁屏上运行。
答案 1 :(得分:0)
托马斯是对的;使用content:
Uri代替file:
Uri为我解决了问题。
请参阅this sample project demonstrating how to serve Files via a ContentProvider中的this SO answer。