resolveUri failing on app private data file

2019-05-20 02:36发布

问题:

I'm generating a bunch of image files when my app first runs, and then trying to use remoteViews.setImageViewUri() later to get these images into my ImageViews. However, when I run the app I'm seeing

01-03 15:05:11.252: W/ImageView(137): Unable to open content: 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 (Permission denied)

Since the file was created by this app, I should have permission to access it from within this app, right? Here's the code I'm using to retrieve it:

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

Any thoughts?

回答1:

Instead of using Uri.parse, use Uri.fromfile.

Uri newUri = Uri.fromFile(file);