Ignoring SSl certificate when debugging in Android WebView
By admin
During development process if you are accessing a web page with SSL certificate you could either get a “Blank Page” or “Page Not Found” error.
To prevent this from happening while developing your app, simply override “onReceivedSslError” of WebViewClient object and continue the execution process.
By doing this, the SSL is being completely ignored and therefore could have a serious result if you forgot to remove the code after development and push the code into production.
To prevent that from happening simply check the build variants.
<pre class="lang:java decode:true ">
webview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
if (BuildConfig.DEBUG) {
handler.proceed(); // Ignore SSL certificate errors
}
}
});