Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle network issues in webview

I am loading a document from google docs into my webview. The problem I see is that when user launch the app and is not connected to network, sees the following screen:

enter image description here

Now if he connects to the network, what is the way to open that link inside webview without re-launching the app. Clicking that link in the webview is one option but can I provide some better user friendly way to reload page in webview if this kind of scenario happens?

like image 514
Piyush-Ask Any Difference Avatar asked Aug 14 '13 01:08

Piyush-Ask Any Difference


1 Answers

You can catch network error in WebViewClient, and show layout which custom by youself, like this:

       webView.setWebViewClient(new WebViewClient() {

            @Override
            public void onReceivedError(final WebView view, int errorCode, String description,
                    final String failingUrl) {
                //control you layout, show something like a retry button, and 
                //call view.loadUrl(failingUrl) to reload.
                super.onReceivedError(view, errorCode, description, failingUrl);
            }
        });
like image 131
JaredLuo Avatar answered Sep 20 '22 01:09

JaredLuo