HAxxor HAxxor - 6 months ago 95
Android Question

How to check if webview failed to load page (android)?

I have a webview in my app, however sometimes due to connectivity the webview fails to load and I get the default webpage unavailable page. I want to show an alertdialog if the webview failed to load. Is there anyway I can check (maybe in the shouldOverridePageLoad function) that a webview loaded successfully? Thanks again

Answer

Use a WebClient on your web view as follow :

webView.setWebViewClient(new WebViewClient(){

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
   // Do something
   }
});
Comments