Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load WebView cached image into an ImageView

I have a WebView that caches its images into a directory using these settings:

mWebView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
mWebView.getSettings().setAppCacheMaxSize( 8 * 1024 * 1024 ); // 8MB
mWebView.getSettings().setAppCachePath(getApplicationContext().getCacheDir().getAbsolutePath());
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAppCacheEnabled(true);

I want to be able to load an image that is cached using this WebView into an ImageView.

I was looking into the directory where the cache dir points to using adb shell (/data/data/com.example.webviewtest/cache), and I found the following folders:

  • ApplicationCache.db
  • com.android.opengl.shaders_cache
  • webviewCacheChromium

Is there some way to find a downloaded image in these directories?

If yes, can I load them into a Bitmap (to use in ImageView)?

like image 574
dors Avatar asked Dec 03 '13 11:12

dors


1 Answers

The resources are saved inside ApplicationCache.db which is an SQLite database. The images you're looking for could be retrieved from the database, but the format of the database may change between Android versions so implementing a compatible way to do this will be hard. I think you'd be better off downloading and caching the images yourself, outside of the WebView.

like image 148
ksasq Avatar answered Nov 10 '22 02:11

ksasq