难道Android的不断从HTTP缓存下载的图片吗? [英] Does Android keeps the images downloaded from HTTP in cache?

查看:77
本文介绍了难道Android的不断从HTTP缓存下载的图片吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的计划如下:

1),显示画面从服务器

1) Display a picture from the server

2)用户修改图片,并将其上传到服务器

2) User change the picture and upload it to the server

3)从服务器显示画面通过重新下载

3) Display the picture by re-downloading from the server

这是我从服务器获取的图片:

This is how I get the picture from the server:

String src = "http://www.getyourpicture.com/mypicture.jpg"
HttpGet httpRequest = new HttpGet(URI.create(src) );
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse)httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();

Bitmap dp = BitmapFactory.decodeStream(instream);
//display dp from here...

这里的问题是,每当我重新下载的形象,但它仍然显示旧照片。 为了证实我已经上传的图片,我已经检查包含服务器上的图片文件夹,甚至参观了浏览器的链接。这两种方法都表明,画面确实被上传。所以,我已经缩小的可能性,Android的可能有一个HTTP缓存管理器,它是不是令人耳目一新的图片链接。

The problem here is, whenever I "re-download" the image, it still shows the old picture. To confirm that I've uploaded the picture, I've checked the folder containing the picture on the server and even visited the link on a browser. Both approaches show that the picture is indeed been uploaded. So I've narrowed down to the possibility that Android might have a http caching manager that is not "refreshing" the image link.

所以,如果回答我的问题是是,我怎么能强制应用程序不使用缓存?

So, if the answer to my question is "yes", how can I force the application to not use the cache?

如果答案是不,那是什么,我忽略了一点?

If the answer is "no", what is the thing that I've overlooked?

推荐答案

我不知道有关工作的卧底和Android上的HTTP请求缓存的缺省值,但如果是体面的,那么它应该在理论上足以增加与时间戳请求的URL查询字符串来触发一个全新的,fullworthy HTTP请求。​​

I'm not sure about the undercovers working and the defaults of HTTP request caching on Android, but if it is decent, then it should in theory suffice to add a query string with a timestamp to the request URL to trigger a brand new and fullworthy HTTP request.

String src = "http://www.getyourpicture.com/mypicture.jpg?" + System.currentTimeMillis();

这篇关于难道Android的不断从HTTP缓存下载的图片吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆