Issue
I have an app with WebView and I want the app to save the website the first time it is connected to the internet so that a further connection is no longer needed. I know some people are saving WebView pages to cache. I've done some research and I found some answers like this one.
But the problem is that I would need some example code on how to do this. Could someone give me an example on how to save a webpage .html file to external storage on Android?
This is the only code i've got at the moment to load a webpage.
//Connecting to UI elements
webView = (WebView) findViewById(R.id.webView1);
//Loading WebView URL
webView.loadUrl("https://www.easistent.com/urniki/izpis/263/16515/0/0/1");
I need some example code. I've seen a lot of documentation and guides, examples on this online but nothing I do works. I'd really appreciate a lot if someone gave me an example with comments.
Solution
You can directly use the WebView cache.
Typically, this is activated with the WebSettings.setCacheMode, using the mode LOAD_CACHE_ELSE_NETWORK
Use cached resources when they are available, even if they have expired.
Use like so :
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
However, in your case, the page declares a 'no-cache' option, which may prevent the WebView to store the page in cache altogether.
If you have the hand on the server side, you can also use the Application Caches API (see http://www.html5rocks.com/en/tutorials/appcache/beginner/ for more details on how that works)
Answered By - njzk2
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.