【发布时间】:2015-11-06 03:55:26
【问题描述】:
图像下载后,我将其保存在内部存储中
Android/data/%packagename%/cache 目录。下面是代码。
private class SaveImageToStorage extends AsyncTask<Void,Void,Void>
{
String picName;
Bitmap bitmap;
public SaveImageToStorage(String name, Bitmap bitmap)
{
this.picName = name;
this.bitmap = bitmap;
}
@Override
protected Void doInBackground(Void... params) {
if(bitmap != null && !picName.isEmpty()) {
File file = new File(feedImagesCacheDir.getPath(), extractImageNameFromUrl(picName));
try {
FileOutputStream fos = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.WEBP, 80, fos);
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
}
在这一切之后,我只想在 android 库中打开图像。
我尝试下面的代码,但它不起作用。它显示 Toast“找不到图像”。
所以我尝试删除“file://”,然后它打开画廊,除了损坏的图像图标之外什么都没有。
private void openImageInGallery(){
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://"+getFeedImagesCacheDir().getPath() + "/" + imgName+".webp"), "image/*");
startActivity(intent);
}
我想也许我把它保存在缓存文件夹中,所以它变成了私有的,只能访问我的应用程序。
我该如何解决这个问题?
谢谢。对不起,我的英语不好。
【问题讨论】:
标签: android caching android-image android-gallery android-file