WebView的onReceivedSslError()方法

回眸只為那壹抹淺笑 提交于 2020-01-20 12:52:44

Android应用中WebView访问https SSL证书网页时,Google Play 总是报 WebView 的 onReceivedSslError 错误。为避免谷歌安全警告,要重写WebView的onReceivedSslError方法,此时要弹框提示用户,是否忽略SSL错误,继续访问网页。

@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error{
    final AlertDialog.Builder builder = new AlertDialog.Builder(WechatLoginActivity.this);
    builder.setMessage(R.string.notification_error_ssl_cert_invalid);
    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();
}

若无弹框提示,出现了SSL错误,应用会被google以[违反了广告ID“ ("advertising ID")”政策]为由拒绝。

参考:

解决Google Play审核中的WebViewClient.onReceivedSslError问题

Google play WebViewClient.onReceivedSslError

Android 上线Google play 总是报 WebView 的 onReceivedSslError 错误

Android WebView访问SSL证书网页(onReceivedSslError)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!