I have a webview that must make a LOG when onReceivedError() is called. But the problem is that when i have very bad wifi connection (almost 100% loss) and the webview is showing a Page Not Available html error, the method onPageFinished is being called and onReceivedError is not being called
How can this be solved? I want that when the page is not available the method onReceivedError gets called!
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d("WEBVIEw","ON PAGE FINISHED");
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
Log.d("WEBVIEw","ON PAGE error");
}
});
onPageFinished
will always be triggered even if there is an error. It would be great to have a method called onPageSucceeded - but this is fairly easy to create.
Create a property on the top of the page private boolean webviewSuccess = true;
and
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Log.d("WEBVIEW","ON PAGE FINISHED");
if(webviewSuccess) {
Log.d("WEBVIEW","ON PAGE SUCCEEDED");
}
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
webviewSuccess = false;
Log.d("WEBVIEW","ON PAGE error");
}
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