我的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));
}
});
答案 0 :(得分:0)
您可以使用WebView的clearSslPreferences()函数:
webView.clearSslPreferences()
它将清除您对此WebView对象的决定,您可能会再次收到警告消息。