How To Avoid Security Alert - Your Application Has An Unsafe Implementation Of the WebViewClient.onReceivedSslError Handler


This is a follow up of my previous post where in we saw how to load https pages/URLs from Android Webview. But there was a problem that we needed to solve, which was, Your Application Has An Unsafe Implementation Of the WebViewClient.onReceivedSslError Handler.

To solve this, you need to notify the users of the navigation from https to http. In this post we'll do this by simply adding an alert dialog with Proceed and Cancel buttons. Just add the below code in your corresponding Activity class and you're all done:

@Override
public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your security warning message here");
    builder.setPositiveButton("proceed", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            handler.proceed();
        }
    });
    builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            handler.cancel();
        }
    });
    final AlertDialog dialog = builder.create();
    dialog.show();
}

Try submitting your app now and you should see that there is no more of that Security message which you saw earlier.

See you around.
Share on Google+

About Sujit Horakeri

Sujit Horakeri is a game freak just like any other next door guy you would come across. He is a Web Developer by Profession, Game Developer by Choice.
Connect with him on:
    Blogger
    Facebook

1 comments:

  1. security guard companies venturaca can assist you completely regarding on how to hire the best possible guard! I have got the relief and I would definitely like everyone to utilize their experiences as well!

    ReplyDelete