I am trying to cache the website loaded in WebView but I can\'t get it working if the network connection is OFF.
Cachdirectory is created, cached files are there. Permi
Your use of
engine.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
is telling the WebView to load the page from cache, but if it needs anything that isn't in the cache, it looks to the network, and when you have no connection, it will just give you the "page could not be loaded error." This is because sadly not everything is stored in the cache and even with this setting, you will notice the browser using the network.
The only way to get the WebView to ignore no connection is to use the
engine.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
setting instead. Some images will not load with this setting (because they weren't cached) but it will still load everything it finds in the cache.
One other note unrelated to your question is that in your code, you have setAppCacheMaxSize being used and that has been deprecated in API 18 and above because the WebView manages the cache size itself, so just a heads up about that.