将WebView缓存图像加载到ImageView中

dor*_*ors 6 android caching android-webview webviewclient

我有一个WebView,它使用以下设置将其图像缓存到目录中:

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);
Run Code Online (Sandbox Code Playgroud)

我希望能够将使用此WebView缓存的图像加载到ImageView中.

我正在查看缓存目录指向的目录使用adb shell(/data/data/com.example.webviewtest/cache),我找到了以下文件夹:

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

有没有办法在这些目录中找到下载的图像?

如果是,我可以将它们加载到Bitmap(在ImageView中使用)吗?

ksa*_*asq 3

资源保存在 ApplicationCache.db 中,这是一个 SQLite 数据库。您要查找的图像可以从数据库中检索,但数据库的格式可能会在 Android 版本之间发生变化,因此实现兼容的方法来执行此操作将很困难。我认为您最好在 WebView 之外自己下载和缓存图像。