0

I tried loading a .jsp webpage using android webview, but webview opens with blank page. The same webpage is loaded successfully in chrome browser app. I tried loading the same webview with www.google.co.in and worked. Here is my code.

 WebView webView = (WebView) view.findViewById(R.id.webView);
    webView.getSettings().setJavaScriptEnabled(true);

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            webViewProgressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            webViewProgressBar.setVisibility(View.GONE);
        }


    });
webView.loadUrl(url);

Thanks in advance.

1 Answers1

0

This is happening because of ssl exception. To properly handle SSL certificate validation and avoid application rejection from Google according new Security Policy, Change your code to invoke SslErrorHandler.proceed() whenever the certificate presented by the server meets your expectations, and invoke SslErrorHandler.cancel() otherwise.

For example,

@Override
    public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    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 += " Do you want to continue anyway?";

        builder.setTitle("SSL Certificate Error");
        builder.setMessage(message);
    builder.setPositiveButton("continue", 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();
}

After this changes it will not show warning.

Raman Sharma
  • 159
  • 1
  • 5
  • Thanks, this solution saved my day. I would like to know how did you arrive at SSL error? I desperately tried to log the possible errors. – Sreehari Radhakrishnan Apr 11 '18 at 19:23
  • @Sreehari Radhakrishnan **Beware**.This *solution* `is all over the place.` e.g. [here](https://stackoverflow.com/questions/35720753/android-google-play-warning-ssl-error-handler-vulnerability/35721678) Applications or updates using this approach will be rejected in Google Play. See [this post](https://support.google.com/faqs/answer/7071387). – Jon Goodwin Apr 11 '18 at 19:50