load WebView cached image into an ImageView

拈花ヽ惹草 提交于 2019-11-28 04:03:03

问题


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)?


回答1:


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.



来源:https://stackoverflow.com/questions/20350466/load-webview-cached-image-into-an-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!