【发布时间】:2016-07-30 06:28:57
【问题描述】:
我有一个应用程序,即使没有可用的互联网,我也需要用户查看图像。最初,我向 mysql 数据库发出 volley 请求,并使用解析后的数据通过 Picasso 显示图像。
Picasso.with(context).load(magazineVersions.get(position).getMagazine_image_url()).resize(400, 500).into(holder.iv_magazine);
现在我还响应我的 volley 请求下载图像并将它们存储在名为 .images 的文件夹中,如下所示:-
public ArrayList showJSON(String json) {
ParseJSON pj = new ParseJSON(json);
pj.parseJSON();
image_url = ParseJSON.img_url;
mag_version = ParseJSON.magversion;
download_path = ParseJSON.download_url;
sample_url = ParseJSON.sample_url;
for (String img : image_url) {
downloadImages(img);
}
ArrayList android_version = new ArrayList<>();
for (int i = 0; i < image_url.length; i++) {
MagazineVersion magazineVersion = new MagazineVersion();
magazineVersion.setMagazine_version_name(mag_version[i]);
magazineVersion.setMagazine_image_url(image_url[i]);
magazineVersion.setDownload_url(download_path[i]);
magazineVersion.setSample_url(sample_url[i]);
android_version.add(magazineVersion);
}
return android_version;
}
downloadImages 的代码如下:-
public void downloadImages(String img_url) {
String fileName = img_url.substring(img_url.lastIndexOf('/') + 1, img_url.length());
File file = new File("/storage/emulated/0/.shatayushi/.images" + fileName);
if (file.exists() && !file.isDirectory()) {
Log.d("ImageExists", fileName);
}else
new DownloadImagesAsync().execute(img_url);
}
我想知道如何使用下载的图像而不是存储在服务器上的图像。简单如下:-
if(Images exist in .images folder)
{
//use picasso to display the images stored in the device
}else
{
//use picasso to display the images stored on the server
Picasso.with(context).load(magazineVersions.get(position).getMagazine_image_url()).resize(400, 500).into(holder.iv_magazine);
}
【问题讨论】:
-
感谢您的编辑@MohammadRezaKhatami,您能帮我解决一下吗?
-
yw,也许这个链接为您提供了一个解决方案。 stackoverflow.com/questions/23391523/… -goodluck!
标签: java android mysql android-volley picasso