【发布时间】:2017-05-17 13:53:08
【问题描述】:
我的 webview 应用程序收到 SSL 错误。它会显示一条警告消息,询问是否加载网站。单击是按钮时,它会通过忽略 SSL 错误来加载网站。但是当我重新加载同一个网站时,它不会向我显示处理错误并直接加载网站的警告消息。
所以,我的问题是每次我重新加载网站时如何让 webview 向我显示处理 SSL 错误的警告消息?
我处理 ssl 错误的代码是``
if(error.getPrimaryError()==SslError.SSL_UNTRUSTED)
{
final Dialog sslalertdialog = new Dialog(browser.this);
sslalertdialog.setContentView(R.layout.sslerroralert);
sslalertdialog.show();
TextView sslalertmessage, sslalerttitle;
Button yes,no;
sslalertmessage= (TextView) sslalertdialog.findViewById(R.id.sslerrormessage);
sslalerttitle= (TextView) sslalertdialog.findViewById(R.id.sslerrorTitle);
String message="The Website Security Certificate is Not Trusted." +
"One possible cause of this error is that a self-signed certificate is installed on the Website's server. " +
"Self-signed certificates aren't trusted by browsers because they are generated by Website's server, not by an accredited Certificate Authority (CA)." +
"Another cause of the error is that Someone is trying to intercept your communication." +
"You Should not Proceed,if you have never seen this error message for this Website before." +
"And if you want to proceed ,plz donot provide any sensitive Infomation to the site (like Credit Card Details " +
"Do you want to proceed anyways ?";
sslalerttitle.setText("The Website Cannot be Trusted!");
sslalertmessage.setText(message);
no=(Button) sslalertdialog.findViewById(R.id.NOBUTTON);
yes=(Button) sslalertdialog.findViewById(R.id.YES_BUTTON);
no.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sslalertdialog.dismiss();
handler.cancel();
}
});
yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sslalertdialog.dismiss();
handler.proceed();
padlock.setImageDrawable(getDrawable(R.drawable.ic_warning_red_400_24dp));
}
});
【问题讨论】:
-
那个有什么消息吗?我遇到了同样的问题,每次都需要显示一个对话框。