Android WebView 白屏(证书过期)

 规避方法:

debug 状态则先不管;

release 状态则弹窗警告,让用户自行选择;

webView.setWebViewClient(new BridgeWebViewClient(webView) {

            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                if (BuildConfig.DEBUG) {
                    handler.proceed();
                } else {
                    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                    builder.setMessage("SSL authentication failed. Do you want to continue accessing?");
                    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();

                }
            }
        });

onReceivedSslError 用于处理 SSL 错误;

当 WebView 加载一个使用 SSL 加密的网页时,如果发生 SSL 错误,比如证书验证失败或域名不匹配等情况,WebViewClient 的 onReceivedSslError 方法会被调用;

开发者可以重写这个方法,以实现自定义的 SSL 错误处理逻辑,比如忽略错误、取消加载页面或者进行其他操作。

这个方法可以帮助开发者在 WebView 加载 SSL 加密网页时处理可能出现的安全性问题。 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值