I am having a problem with Webview in that it will not use the cache. I start my app up, load the HTML5 page, then back out of the page, enter airplane mode on the phone, then try to go to the web page again. It should be cached, but I get a message saying that the URL could not be retrieved.
Here is my code pertaining to this. Am I doing something wrong???
String weblink = "http://abcd.com";
final ConnectivityManager conMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
final NetworkInfo activeNetwork = conMgr.getActiveNetworkInfo();
if (activeNetwork != null && activeNetwork.isConnected()) {
progressBar = ProgressDialog.show(this, "Please Wait", "loading online..");
mWebview.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
mWebview.getSettings().setAppCacheMaxSize(1024*1024*8);
mWebview.loadUrl(weblink);
setContentView(mWebview);
}
else
{
progressBar = ProgressDialog.show(this, "Please Wait", "loading offline..");
mWebview.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ONLY);
mWebview.loadUrl(weblink);
setContentView(mWebview);
}
Your code is ok.
Either the Website does not exist or didn't get cached correctly, or your forgot to add the following permissions :
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permisson.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With