Issue
I want to get images from the web page and save them into the local storage. I can find all image URLs from the HTML
, load that images from the server and save them. But I don't want to access to the server second time for the same information which is already in webview
. So I want to know how I can load images from the webview
?
Solution
You can set a WebView
cache in a few steps. Take a look below.
WebView webView = (WebView) findViewById(R.id.your_webView_Id);
String cacheDir = getDir("your_WV_cache_dir", Context.MODE_PRIVATE).getAbsolutePath(); webView.getSettings().setAppCacheMaxSize(1024 * 1024 * 1); // 1 Mb cache limited size > webView.getSettings().setAppCachePath(cacheDir); webView.getSettings().setAppCacheEnabled(true); webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); // This constant is important to you. This way you can load daa from cache, if it was already downloaded once.
You might take a look to th other possible values to the constant above at the WebView.WebSettings
official documentation.
Let me know if it works.
Answered By - yugidroid
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.