I tried using onReceivedError both inside shouldOverrideUrlLoading () and outside of this method, but in a WebViewClient. I even tried in the main class Activity. I was dissatisfied with the inconsistent results. Therefore, I decided to use the test method isOnline () and call it before calling loadUrl ().
public boolean isOnline() { ConnectivityManager cm = (ConnectivityManager) getBaseContext() .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo i = cm.getActiveNetworkInfo(); if ((i == null) || (!i.isConnected())) { Toast toast = Toast.makeText(getBaseContext(), "Error: No connection to Internet", Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 0); toast.show(); return false; } return true; }
Then this onReceivedError is in the WebViewClient, but outside the overloadurltingy method. This seems to constantly prevent the dumb, grinning android error pages.
@Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if (view.canGoBack()) { view.goBack(); } Toast toast = Toast.makeText(getBaseContext(), description, Toast.LENGTH_SHORT); toast.setGravity(Gravity.TOP | Gravity.CENTER, 0, 0); toast.show(); }
Some people may find this resource difficult. Well, not as hard as Android Android and Google+ apps. And not Google services. I honestly don't mind using a little oxygen. Call me a bad guy ...
R Earle Harris Apr 13 '13 at 20:55 2013-04-13 20:55
source share