Android WebView加载网页后一片空白
程序员文章站
2022-06-04 14:40:48
...
很可能是SSL证书存在问题导致网页无法加载,应该在设置WebViewClient并且在WebViewClient中重写onReceivedSslError,创建一个弹框,让用户选择是否继续信任该网站,如下:
mWebView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
final AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
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;
default:
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();
}
}
上一篇: 关于Osmdroid的一切
推荐阅读
-
Android中WebView加载网页设置进度条
-
android WebView加载html5介绍
-
详解Android Webview加载网页时发送HTTP头信息
-
Android webview旋转屏幕导致页面重新加载问题解决办法
-
Android获取WebView加载url的请求错误码 【推荐】
-
Android开发实现webview中img标签加载本地图片的方法
-
详解android 用webview加载网页(https和http)
-
Android webview如何加载HTML,CSS等语言的示例
-
Android 自定义标题栏 显示网页加载进度的方法实例
-
Android中WebView加载网页设置进度条