在android中webview请求网页时,有的网页跳转会报这个错,我之前代码是:
WebViewClient mWebviewclient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
};
webView.setWebViewClient(mWebviewclient);
网上查了帖子,说是将
webView.setWebViewClient(mWebviewclient);
改为
webView.setWebChromeClient(new WebChromeClient());
这样确实能解决问题,但是会导致其它问题,比如说我想在方法onReceivedSslError()或者onReceivedError()中做些处理,这时就很棘手,我的解决办法是,
WebViewClient mWebviewclient = new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return super.shouldOverrideUrlLoading(view, url);
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
@Override
public void onReceivedError(WebView view, int errorCode,
String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
}
};
webView.setWebViewClient(mWebviewclient);
就是在 shouldOverrideUrlLoading()方法中,将view.loadUrl(url)方法去掉就好~