How to check url is loaded in webview or not

kaibuki picture kaibuki · Dec 2, 2011 · Viewed 14.3k times · Source

I am loading url in android webview using below code

webviewShowPost.loadUrl(URL);

I want to check if no data connectivity available then webview instead of showing blank view, I can display Toast of no connectivity.

Thanks

Answer

Sandy picture Sandy · Dec 2, 2011

Please try this

webView.setWebViewClient(new WebViewClient() { 
        @Override
        public void onReceivedError(WebView view, int errorCode,
                String description, String failingUrl) {
            // TODO Auto-generated method stub
            super.onReceivedError(view, errorCode, description, failingUrl);
        }
        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);
        }


    });