Using the WebClient you should write about the method onReceivedSslError () .
onReceivedSslError () Notifies the host application that it
An SSL error occurred while loading a resource. The host application must
call handler.cancel()
or handler.proceed()
.
Example:
WebView view=(WebView) v.findViewById(R.id.wv_noticias);
view.getSettings().setJavaScriptEnabled(true);
webview.setWebViewClient(new WebViewClient() {
...
...
...
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
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 += "\"SSL Certificate Error\" Do you want to continue anyway?.. YES";
handler.proceed();
Log.e(TAG, onReceivedSslError: " + message);
}
});
The common thing is to cancel the load but in this case it simply indicates that I continued with handler.proceed()
Update:
In the case of uploading an application to the Google Play Store, care must be taken as it will probably not be accepted, the reason is that if an SSL error occurs the page should not be loaded, otherwise it should be canceled, due to issues of security.
link
For this you must implement a dialog which indicates to the user if you want to proceed or cancel the upload, with this your application can be uploaded to Google Play Store without problem.
@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
final AlertDialog.Builder builder = new AlertDialog.Builder(CustomWebView.this);
String message = "";
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;
default:
break;
}
message += "\"SSL Certificate Error\" Deseas continuar?";
builder.setTitle("SSL Certificate Error");
builder.setMessage(message);
builder.setPositiveButton("continuar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();
}
});
builder.setNegativeButton("cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
builder.create().show();
}