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
You might often face issues in updating the chrome and Android System Webview. To fix this problem, you can reboot your device, check your internet connection, stop auto-updating all apps, clear Google Playstore cache, and storage, leave the beta testing program, and manually update Android WebView app from Playstore.
Modify src/MainActivity. java file to add WebView code. Run the application and choose a running android device and install the application on it and verify the results. Following is the content of the modified main activity file src/MainActivity.
The WebView class is an extension of Android's View class that allows you to display web pages as a part of your activity layout. It does not include any features of a fully developed web browser, such as navigation controls or an address bar. All that WebView does, by default, is show a web page.
Use a WebClient on your web view as follow :
webView.setWebViewClient(new WebViewClient(){ @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { super.onReceivedError(view, request, error); // Do something } });
Extending on Damien's answer on using WebViewClient
, there are four listeners available on WebViewClient
to check for the success and failure of loading web pages.
webView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { } @Override public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) { } @Override public void onReceivedHttpError( WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { } });
There is also:
@Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { } });
which is deprecated in favor of its overload mentioned in the above code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With