Android - WebView onReceivedError opposite

386 views Asked by At

How do I know if there were no errors in loading a page in webview? Here is the code for the onReceivedError:

    mWebView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            view.stopLoading();  // may not be needed
            switch (Locale.getDefault().toString()) {
                case "es_ES":
                    view.loadUrl("file:///android_asset/www/errorPage.forRestActivities.es_ES.HTML");
                    break;
                default:
                    view.loadUrl("file:///android_asset/www/errorPage.forRestActivities.en_US.HTML");
                    break;
            }
        }

    });
2

There are 2 answers

2
Erik Duisters On

I would use onPageFinished() for that.

0
AudioBubble On

Setting a flag (isError) did the trick. The flag is set to false when created, as an error is not what's supposes to happens. If it does happens then the flag is set to true. That flag is evaluated at onPageFinished. If it's true the buttons are not showed otherwise they're