gpt4 book ai didi

android - Webview 显示来自的不安全内容

转载 作者:行者123 更新时间:2023-11-29 19:15:11 24 4
gpt4 key购买 nike

我已经在我的 Android 应用程序中实现了 WebView 。它在 android marshmallow 中完美显示网页,但一台 android 4.1.1 设备不显示页面。我已经添加了这段代码

public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}

对于 SSL 错误。

但是在 4.1.1 设备中也没有显示页面的变化

something.com 的页面显示来自

的不安全内容

有什么帮助吗?

最佳答案

To Solve Google Play Warning: WebViewClient.onReceivedSslError handler

并不总是强制 handler.proceed(); 但你还必须包括 handler.cancel();这样用户就可以避免加载不安全的内容。

处理 WebViewClient.onReceivedSslError 处理程序的不安全实现

使用下面的代码

 webView.setWebViewClient(new SSLTolerentWebViewClient());
webView.loadUrl(myhttps url);

创建类,

private class SSLTolerentWebViewClient extends WebViewClient {
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {

AlertDialog.Builder builder = new AlertDialog.Builder(Tab1Activity.this);
AlertDialog alertDialog = builder.create();
String message = "SSL Certificate error.";
switch (error.getPrimaryError()) {
case SslError.SSL_UNTRUSTED:
message = "The certificate authority is not trusted.";
break;
case SslError.SSL_EXPIRED:
message = "The certificate has expired.";
break;
case SslError.SSL_IDMISMATCH:
message = "The certificate Hostname mismatch.";
break;
case SslError.SSL_NOTYETVALID:
message = "The certificate is not yet valid.";
break;
}

message += " Do you want to continue anyway?";
alertDialog.setTitle("SSL Certificate Error");
alertDialog.setMessage(message);
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Ignore SSL certificate errors
handler.proceed();
}
});

alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

handler.cancel();
}
});
alertDialog.show();
}
}

关于android - Webview 显示来自的不安全内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43776175/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com