I use webview to load html pages and urls.
I want to load url only if internet is available or if the url content is cached by the web view.
How can I check if a url is cached without having to create my own cache on some external path.
WebSettings ws = wv.getSettings();
ws.setJavaScriptEnabled(true);
ws.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
wv.setOnTouchListener(this);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!url.contains("http")) {
view.loadUrl(url);
} else {
if (Utils.isConnectingToInternet(thisActivity)) {
view.loadUrl(url);
}
}
view.loadUrl(url);
return false;
}
I have referred to :
WebView Cache Data Directory?
Check if file already exists in webview cache android
How to move webView cache to SD?
Android webview check if page is in cache