I am trying to get the HTML5 offline cached version of a website to display when the network is down inside of a webview.
我正在试图让HTML5离线缓存版本的网站显示当网络在一个webview的内部。
I have overridden onReceivedError ok, and when the network is down this method is called. Problem is that it displays the generic "Web Page is not available" message.
How can I get it to display the HTML5 cached version of the page? The offline storage of the webapp is definately working, as it works fine in the desktop version of Firefox and Chrome.
Note: If I set some dummy data in loadData such as view.loadData(Uri.encode("
Page load failed
"), "text/html", "UTF-8"); and then click back (by detecting back event and calling webview.goBack(); then the cached version of the page is displayed ok.
注意:如果我在loadData(如view.loadData)中设置一些假数据(Uri)。编码(“
页面加载失败 div > html >”),“text / html”、“utf - 8”);然后单击back(通过检测返回事件并调用webview.goBack();然后显示页面的缓存版本。
Here are some lines of code I added to setup the webview:
I think a good solution would be to use LOAD_NORMAL and onReceivedError Navigate BACK. I think this will load the cache according to the documentation (not sure if I remember correctly) but be carefull no to get stuck in an infinite loop
Override the way the cache is used. The way the cache is used is based on the navigation option. For a normal page load, the cache is checked and content is re-validated as needed. When navigating back, content is not revalidated, instead the content is just pulled from the cache. This function allows the client to override this behavior.
Thats it if your internet is on your webpage open normal version and saved in cached and if your internet is off then it automatically open in cached version.