2

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

我在 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. 我可以将应用程序缓存文件夹与图库一起使用吗?

4

0 回答 0