我尝试使用android webview加载.jsp网页,但是webview打开时显示空白页面。在Chrome浏览器应用中成功加载了相同的网页。我尝试使用www.google.co.in加载相同的webview并且工作。这是我的代码。
WebView webView = (WebView) view.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
webViewProgressBar.setVisibility(View.VISIBLE);
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
webViewProgressBar.setVisibility(View.GONE);
}
});
webView.loadUrl(url);
提前致谢。
答案 0 :(得分:0)
由于ssl异常,这种情况正在发生。要根据新的安全策略正确处理SSL证书验证并避免Google拒绝应用程序,只要服务器提供的证书符合您的期望,就更改您的代码以调用SslErrorHandler.proceed(),否则调用SslErrorHandler.cancel()。
例如,
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
String message = "SSL Certificate error.";
switch (error.getPrimaryError()) {
case SslError.SSL_UNTRUSTED:
message = "The certificate authority is not trusted.";
break;
case SslError.SSL_EXPIRED:
message = "The certificate has expired.";
break;
case SslError.SSL_IDMISMATCH:
message = "The certificate Hostname mismatch.";
break;
case SslError.SSL_NOTYETVALID:
message = "The certificate is not yet valid.";
break;
}
message += " Do you want to continue anyway?";
builder.setTitle("SSL Certificate Error");
builder.setMessage(message);
builder.setPositiveButton("continue", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
final AlertDialog dialog = builder.create();
dialog.show();
}
更改后,它不会显示警告。