Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Android keeps the images downloaded from HTTP in cache?

This is how my programme works:

1) Display a picture from the server

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

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...

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?

like image 903
Creniale Avatar asked Apr 07 '11 02:04

Creniale


1 Answers

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();
like image 188
BalusC Avatar answered Sep 25 '22 15:09

BalusC