Android 应用程序私有数据文件上的resolveUri失败

Android 应用程序私有数据文件上的resolveUri失败,android,file-io,android-appwidget,remoteview,Android,File Io,Android Appwidget,Remoteview,当我的应用程序第一次运行时,我会生成一组图像文件,然后尝试稍后使用RemoteView.setImageViewUri()将这些图像放入我的ImageView中。但是,当我运行应用程序时,我看到 01-03 15:05:11.252:W/ImageView(137):无法打开内容: file:///data/data/com.nickavv.cleanwidgets/files/batt_s_19.png 01-03 15:05:11.252:W/ImageView(137):java.io.F

当我的应用程序第一次运行时,我会生成一组图像文件,然后尝试稍后使用RemoteView.setImageViewUri()将这些图像放入我的ImageView中。但是,当我运行应用程序时,我看到

01-03 15:05:11.252:W/ImageView(137):无法打开内容: file:///data/data/com.nickavv.cleanwidgets/files/batt_s_19.png 01-03 15:05:11.252:W/ImageView(137):java.io.FileNotFoundException: /data/data/com.nickavv.cleanwidgets/files/batt_s_19.png(许可 拒绝)

由于该文件是由该应用程序创建的,因此我应该有权从该应用程序中访问该文件,对吗?下面是我用来检索它的代码:

   File file = new File(context.getFilesDir().getPath(), idName+".png");
   Uri newUri = Uri.fromFile(file);
   myViews.setImageViewUri(id, newUri);

有什么想法吗?

不要使用
Uri.parse
,而是使用
Uri.fromfile

Uri newUri = Uri.fromFile(file);

这将我的错误更改为:
01-03 15:05:11.252:W/ImageView(137):无法打开内容:file:///data/data/com.nickavv.cleanwidgets/files/batt_s_19.png 01-03 15:05:11.252:W/ImageView(137):java.io.FileNotFoundException:/data/data/com.nickavv.cleanwidgets/files/batt_s_19.png(权限被拒绝)
添加到Clarity的原始帖子中,这是一个权限问题。URI是正确的,但不允许您访问该文件。您的
RemoteView
与生成图像的过程是否不同?图像是在小部件的OnEnabled方法中生成的,我正在尝试使用OnUpdate方法访问它们。我的印象是,只要我在同一个应用程序内的同一个应用程序中访问私人文件,我就可以访问这些文件,这是真的。使用小部件中的
remoteview
,可能是在不同的过程中访问URI的原因。您可以尝试使用创建文件。请注意,这在API 17中已被弃用,描述中列出了一些替代方案。事实证明,我只在API级别10及以下使用这整段代码,因此弃用不应该是一个问题。这似乎已经解决了这个问题,所以谢谢你!