I did not find a special solution to hide the default errors displayed by webviews in Android. I can display my own error messages by putting specific errors in error codes.
The problem is that before user error messages appear, I see WebView errors in a split second, and then after that my user errors are displayed.
Below is a snippet of code that handles errors and displays my own error messages:
protected void onPostExecute(String S) { mWebView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errCode, String errDescription, String failingUrl ) { view.clearView(); Toast.makeText(getApplicationContext(), "Error code is "+errCode, Toast.LENGTH_SHORT).show(); if(errCode == -2 || errCode == -8) { view.loadData("There seems to be a problem with your Internet connection. Please try later", "text/html", "UTF-8"); } if(errCode == -14) { view.loadData("Page cannot be found on server", "text/html", "UTF-8"); } } }); mWebView.loadUrl(url); ShowProgress.dismiss(); }
Can anyone suggest any changes or tips on how to hide web browsing errors and only display my custom error messages? Thanks for stopping by and reading this post.
source share