Reputation: 1973
I know this kind of silly question. however, I was trying to save an html page in my app, just in case the user has no connectivity. I did the following but failed:
if(CheckConnectivity())
{mWebView.loadUrl("http://www.google.com");}
else {mWebView.loadUrl("file:///android_asset/offline.html");}
Then I dragged the offline.html to my assets folder. for CheckConnectivity I did this:
private boolean CheckConnectivity() {
ConnectivityManager CK = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = CK.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
return false;
Is there something wrong? Do I have to do anything in the manifest?
Upvotes: 0
Views: 301
Reputation: 1973
Well, I found a solution: I got rid of the else statement in the first If. then I placed it under setWebViewClient into:
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
mWebView.loadUrl("file:///android_asset/html/offline.html");
}
Upvotes: 1