Skip to content Skip to sidebar Skip to footer

Android - Webviewclient Onreceivedhttperror Determine If Is Main Resource

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

Solution 1:

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)
                    }
                }

            }

Post a Comment for "Android - Webviewclient Onreceivedhttperror Determine If Is Main Resource"