Load HTTPS Pages/URLs in Android Webview

It is a very common and known issue that we cannot load pages with the SSL in Android Webview. The solution to this could be varying from making code changes to the backend so that the service recognizes this situation and redirects to a non SSL based resources to overriding the onReceivedSslError method.

However, when we do not have control on the backend services, we somehow need to fix this from the tools that we have access to. In that case the obvious solution is to override the onReceivedSslError method. Paste the below code in your corresponding Activity class:

public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {

This will work just fine when you test your app in your phone or on the simulator. When you submit your app to the Play Store, you could possibly get the following Security alert

Security alert Your application has an unsafe implementation of the WebViewClient.onReceivedSslError handler. 

Rightly so, since you are doing this without letting the user know about the navigation from https to http. We will solve this issue in the next post.

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:


Post a Comment