Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Webview: E/chromium: [ERROR: ssl_client_socket_impl. cc (1141)]

When I load my https url into webview in android, I got the error in logcat like below

E/chromium: [ERROR:ssl_client_socket_impl.cc(1141)] handshake failed; returned -1, SSL error code 1, net_error -101

Due to this CSS and JS is not loaded into webview properly.

I have gone through the this link. But when I load the same URL at second time it's working properly. I am using android 5.0.

Please some help me out from this issue.

like image 310
Raja Peela Avatar asked Oct 05 '16 12:10

Raja Peela


2 Answers

use

 @Override
 public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
     handler.proceed();
 }

in your set webview client method

like image 86
Edrisa Turay Avatar answered Oct 27 '22 23:10

Edrisa Turay


Here is the full solution for WebView.

private void loadWebView(String myUrl) {

    WebView webView = findViewById(R.id.webView);
    ProgressDialog progressdialog = new ProgressDialog(StartModelTest.this);
    progressdialog.setMessage("Please wait...");
    progressdialog.setCanceledOnTouchOutside(false);

    /* JS start*/
    WebSettings settings = webView.getSettings();
    settings.setDomStorageEnabled(true);
    settings.setJavaScriptEnabled(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    /*  JS start*/

    Log.d("TAG", "loadWebView: "+myUrl);
    webView.loadUrl(myUrl);
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            if (!progressdialog.isShowing()) {
                Log.d("TAG", "Started: ");
                progressdialog.show();
            }
        }

        public void onPageFinished(WebView view, String url) {
            if (progressdialog.isShowing()) {
                progressdialog.dismiss();
                Log.d("TAG", "Finished: ");
            }
            //Log.d("TAG", "onPageFinished Bool: " + url.contains("home"));
            if (url.contains(Util.CLOSING_TAG)) {
                finish();
            }
        }

        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            if (progressdialog.isShowing()) {
                progressdialog.dismiss();
                Log.d("TAG", "Err: ");
            }
        }
    });
}
like image 22
Motiur Rahaman Avatar answered Oct 28 '22 00:10

Motiur Rahaman