Skip to content
Advertisement

Only some URLs not loading in Webview

Code

    final WebView mWebView = (WebView) rootView.findViewById(R.id.webview);
    mWebView.setWebViewClient(new WebViewClient());
    mWebView.getSettings().setLoadsImagesAutomatically(true);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    mWebView.loadUrl("https://www.onlineradiofm.in/");

Im trying to load this URL in webview and the webview is empty. What’s wrong with this URL? I tried replacing the URL with other links and it works perfectly.

Advertisement

Answer

It’s been a SSL handshake failed for HTTPS URL.

for debugging the webview, pls add following line and you can inspect webview Using chrome browser chrome://inspect.

     WebView.setWebContentsDebuggingEnabled(true);
   

Step-1: Create a webclient:

    WebViewClient client = new WebViewClient(){
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, 
                                       SslError error) {
            //super.onReceivedSslError(view, handler, error);
            handler.proceed(); // which ignores ssl errors and proceed further
        }
    };

Step-2: add client into webview

    mWebView.setWebViewClient(client);

Happy coding…

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement