Google Play应用已被拒绝 - SSL错误处理程序

时间:2018-02-21 14:32:20

标签: android google-play android-webview android-security sslerrorhandler

以下是我从Google Play收到的消息。

enter image description here

阅读完邮件后,我会看一下Google Help Center article。对于我的想法,这应该与WebViewClient的类以及onReceivedSslErrorSslErrorHandler.proceed()SslErrorHandler.cancel()等一些方法相关。然后在我的项目中,我尝试搜索一些关键字,例如WebViewClientSslErrorHandleronReceivedSslError。我也得到了Nothing的结果。

有任何解决此问题的建议吗?

1 个答案:

答案 0 :(得分:0)

显示带有继续和取消的弹出窗口或对话框。
继续 handler.proceed()
取消 handler.cancel()

我们需要询问用户,当这个错误发生时,是继续还是停止。

像这样

val builder = AlertDialog.Builder(cntx)
        var message = "SSL Certificate error."
        when (error?.primaryError) {
            SslError.SSL_UNTRUSTED -> message = "The certificate authority is not trusted."
            SslError.SSL_EXPIRED -> message = "The certificate has expired."
            SslError.SSL_IDMISMATCH -> message = "The certificate Hostname mismatch."
            SslError.SSL_NOTYETVALID -> message = "The certificate is not yet valid."
        }
        message += " Do you want to continue anyway?"

        builder.setTitle("SSL Certificate Error")
        builder.setMessage(message)
        builder.setPositiveButton(
            "continue"
        ) { dialog, which -> handler?.proceed() }
        builder.setNegativeButton(
            "cancel"
        ) { dialog, which -> handler?.cancel() }
        val dialog = builder.create()
        dialog.show()