1. 程式人生 > >Android 上線Google play 總是報 WebView 的 onReceivedSslError 錯誤

Android 上線Google play 總是報 WebView 的 onReceivedSslError 錯誤

onReceivedSslError 是WebView的一個方法

解決辦法,直接把下面程式碼貼上到你的專案中就可以了。

//下面的方法解決Android6.0載入不出webView的問題
@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();

}