本文介绍了的WebView避免谷歌安全警告在实施onReceivedSslError发挥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个链接,这将在web视图打开。现在的问题是,直到我重写onReceivedSslError这样它不能打开:

  @覆盖
        公共无效onReceivedSslError(的WebView视图,SslErrorHandler处理器,SslError错误){
            handler.proceed();
        }

从谷歌

我收到安全警报玩话说:

If I remove onReceivedSslError (handler.proceed()), page won't open.
Is there anyway I can open page in webview and avoid security alert.

解决方案

As email said, onReceivedSslError should notify user is going to a page with invalid cert. You should not proceed it directly.

For example, I add an alert dialog to make user have confirmed and seems Google no longer shows warning.


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

这篇关于的WebView避免谷歌安全警告在实施onReceivedSslError发挥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-19 08:08