ImageViewer意图显示空白图像

时间:2018-02-06 08:56:38

标签: android android-intent uri image-viewer

我在运行时将图像保存在缓存下。然后我想阅读并用系统图像查看器显示它。

我在api级别24下使用以下代码:

File f = new File(getApplicationContext().getCacheDir(), "sample.png"); 

Intent intent = new Intent(Intent.ACTION_VIEW);               
Uri uri = Uri.fromFile(f);
imgView.setImageURI(uri); // It works 
intent.setDataAndType(uri,"image/*");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(intent); // It shows an blank image

修改 上层代码适用于/sdcard/test.jpg。我可以在图库中使用app cache文件夹吗?

0 个答案:

没有答案