这些是我对WebView的回调,但是没有一个回复我的TimeOut错误,还有其他我可以添加以获取它们吗?
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
super.onReceivedError(view, request, error);
webViewError = true;
errorMessageView.setText(getString(R.string.unknown_error) + " " + error.toString());
}
@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
webViewError = true;
errorMessageView.setText(getString(R.string.unknown_error) + " " + errorResponse.toString());
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
super.onReceivedSslError(view, handler, error);
webViewError = true;
errorMessageView.setText(getString(R.string.ssl_error));
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
setUpView();
}
});
答案 0 :(得分:0)
只有当设备具有Android M.
时才会调用您使用过的onReceivedError(WebView view, WebResourceRequest request, WebResourceError error)
要支持其他版本,您必须使用已弃用的onReceivedError(WebView view, int errorCode, String description, String failingUrl)
。
像这样:
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
//Handle the error
super.onReceivedError(view, errorCode, description, failingUrl);
}
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onReceivedError(WebView view, WebResourceRequest req, WebResourceError rerr){
onReceivedError(view, rerr.getErrorCode(), rerr.getDescription().toString(), req.getUrl().toString());
}