Android - Webviewclient onReceivedHttpError detects if main resource

WebViewClient.onReceivedError

deprecated, now I have to use onReceivedHttpError

webview for error handling, however this method gets error from any resource which I don't want.

I only want to detect the failed master url .

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

I tried using the method request.getUrl()

, but it is only compatible with API 23.

0


source to share


1 answer


Meanwhile, I ended up with 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)
                    }
                }

            }

      

+1


source







All Articles