我有一个webview,必须在调用onReceivedError()时生成一个LOG。但问题是,当我有非常糟糕的wifi连接(几乎100%丢失)并且webview显示页面不可用的html错误时,正在调用onPageFinished方法并且不调用onReceivedError
如何解决这个问题?我希望当页面不可用时,会调用onReceivedError方法!
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");
}
});
答案 0 :(得分:7)
onPageFinished
。有一个名为onPageSucceeded的方法会很棒 - 但这很容易创建。
在页面顶部private boolean webviewSuccess = true;
和
@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");
}