2

WebViewClient.onReceivedError was deprecated, now I have to use onReceivedHttpError to handle the webview errors, however this method receives the error from any resource, which is not what I desire.

I wish only to detect the main URL failing.

How should I detect the error if I am using API 10?

I tried using the request.getUrl() method but it is only compatible with API 23.

htafoya
  • 18,261
  • 11
  • 80
  • 104

1 Answers1

4

Meanwhile, I ended up doing this:

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                //your thing (f.e. show error message)
            }

            @Override
            public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {

                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                   //url is the original loading url
                    if(request.getUrl().equals(url)) { 
                        //your thing (f.e. show error message)
                    }
                }

            }
htafoya
  • 18,261
  • 11
  • 80
  • 104