Hide webview errors in android

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.

+4
source share
2 answers

I could not find a specific solution, as this is error # 2340 . So I take the web view from the application and use a regular browser instead.

+2
source

Try adding this:

 view.stopLoading(); 

The source code will be like this:

 protected void onPostExecute(String S) { mWebView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errCode, String errDescription, String failingUrl ) { try { view.stopLoading(); } catch(Exception e){} 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(); } 
+1
source

All Articles