Pein
Pein

Reputation: 1079

How to programmatically send message to webview about error

I have webView on activity. How can I send message about error to this webView in order to load error web page?

Upvotes: 0

Views: 1400

Answers (2)

Sahir Saiyed
Sahir Saiyed

Reputation: 530

please explain your question in detail. according to my understanding send custom error code using Intent on basis of error code show error web page.

     WebView wv = (WebView) findViewById(R.id.webView);
         wv.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);                    
Log.i("WEB_VIEW_TEST", "error code:" + errorCode);
    mWebView.loadUrl("file:///android_asset/myerrorpage.html");

            }
         });

Upvotes: 1

wvdz
wvdz

Reputation: 16641

I assume there was an error on the website that was loaded, and you want to communicate this to the app.

You can use Javascript binding for this.

If you meant the other way around: there is an error in the app and you want to show an error page, you can simply load a different url using webView.loadUrl(...)

Upvotes: 1

Related Questions