Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Android's System Cache
    text
    copied!<p>I would like to use Android's system cache when downloading images as per these previous instructions: <a href="https://stackoverflow.com/questions/1945201/android-image-cache/3893959#3893959">android system cache</a>. I was able to get the following code working but the log statements are telling me that the images are never being read from the cache. </p> <pre><code>try { //url = new URL("http://some.url.com/retrieve_image.php?user=" + username); URL url = new URL("http://some.url.com/prof_pics/b4fe7bdfa174ff372c9f26ce6f78f19c.png"); URLConnection connection = url.openConnection(); connection.setUseCaches(true); Object response = connection.getContent(); if (response instanceof Bitmap) { Log.i("CHAT", "this is a bitmap"); current_image.setImageBitmap((Bitmap) response); } else { Log.i("CHAT", "this is not a bitmap"); Log.i("CHAT", response.toString()); InputStream is = connection.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); current_image.setImageBitmap(BitmapFactory.decodeStream(bis)); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>I have tried two different types of requests, one is to go through a PHP script that returns the image and another that is directly accessing the image file. I refresh the same image multiple times in a row and it never seems to get cached. For the direct image access, I get: </p> <pre><code>05-31 23:45:12.177 I/CHAT ( 2995): this is not a bitmap 05-31 23:45:12.177 I/CHAT ( 2995): org.apache.harmony.luni.internal.net.www.protocol.http.FixedLengthInputStream@40c1c660` </code></pre> <p>For the indirect image access, I consistently get:</p> <pre><code>05-31 23:45:14.550 I/CHAT ( 2995): this is not a bitmap 05-31 23:45:14.550 I/CHAT ( 2995): org.apache.harmony.luni.internal.net.www.protocol.http.ChunkedInputStream@40c02448 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload