I have a Android app that uses the webview. There is a java backend server that serves up all the front end files and builds the cache manifest over apache tomcat.
My problem is that I'm unsure how to get the webview to load from the app cache when the server is not connected, but the device is otherwise connected to the internet.
If I go into the app code, I can force it to the use the cache with
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
So I know my files are appropriately being cached. I also tried solutions from other stack overflow questions which had me check the status of the network and setting the cache mode based on the network status like this:
cm = (ConnectivityManager) this.getSystemService(Activity.CONNECTIVITY_SERVICE);
if(cm.getActiveNetworkInfo().isConnected()) ....
However, this doesn't work in the case where the device is online, but my server is down. It still says the network is fine in that case and doesn't load from the cache.
The ideal solution would be that when the front end webview tries to access a resource over the network and it's unavailable, it just loads from the cache, which is exactly how it works in a normal browser. But I can accept workarounds, like have the app detect the network connection to my specific server and changing the cache mode accordindly.
Anyone know the best approach for this problem? Thanks.