Aja*_*dya 8 ssl android webview
我在Playstore上标记了一个问题,谷歌发送邮件我的应用程序是不安全的,因为使用SSL.
目前在我的应用程序中,我有一个webview是加载链接,它包含https网址.
在网页设置我这样做:
web.setWebViewClient(new SSLTolerentWebViewClient());
忽略ssl证书我使用下面的代码,但由于忽略证书playstore显示我的应用程序是不安全的
private class SSLTolerentWebViewClient extends WebViewClient {
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed(); // Ignore SSL certificate errors
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我如何做到这一点,所以我WebView可以处理https网址和Playstore不标记我的应用程序不安全?
Pra*_*ank 29
解决Google Play警告:WebViewClient.onReceivedSslError处理程序
并非总是强制执行handler.proceed(); 但你还必须包括handler.cancel(); 这样用户可以避免加载未说明的内容.
处理WebViewClient.onReceivedSslError处理程序的不安全实现
使用以下代码
webView.setWebViewClient(new SSLTolerentWebViewClient());
webView.loadUrl(myhttps url);
Run Code Online (Sandbox Code Playgroud)
和
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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18208 次 |
| 最近记录: |