Hareesh
Hareesh

Reputation: 943

Webview not able to load https url in android?

I am implementing webview application in android. When i am trying to load https url one or two times it finishes the activity. Agian trying to load https url it shows webpage not available. please find below image what i got.

enter image description here

When i click on that url again, then it shows the websit.

I used the below code for loading the url.

webView = (WebView) findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true); 
webView.loadUrl("https://www.facebook.com");
webView.clearView();
webView.measure(100, 100);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);



    webView.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

        @SuppressLint("NewApi")
        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler,     SslError error) {
            super.onReceivedSslError(view, handler, error);

            // this will ignore the Ssl error and will go forward to your site
            handler.proceed();
            error.getCertificate();
        }
    });

please any help guys.......

Thanks in advance

Upvotes: 17

Views: 31739

Answers (9)

jakub.g
jakub.g

Reputation: 41238

December 2016 answer:

If this happens only on certain devices with Android 5+ and only on certain pages, it's most likely due to this chromium bug:

https://www.chromium.org/developers/androidwebview/webview-ct-bug

The solution is to either:

  • tell customers to update webview to 55+ (might not be easy on all devices)
  • tell customers to move their system clock backward a few weeks (not a nice solution)
  • get a non-Symantec cert

Upvotes: 0

Zahra.HY
Zahra.HY

Reputation: 1692

You should remove this

super.OnReceiveSslError(view,handler,error);

Upvotes: 3

Alex
Alex

Reputation: 201

Delete this string:

super.onReceivedSslError(view, handler, error);

and in this method

public boolean shouldOverrideUrlLoading(WebView view, String url) {

turn return to false
like this:

 return false;

It helped me

Upvotes: 5

zhangweiheb
zhangweiheb

Reputation: 79

Add this overriding method to your WebViewClient implementation. You'll need to compile it with Android SDK 2.2 (API level 8) or later. The method appears in the public SDK as of 2.2 (API level 8) but we've tested it on devices running 2.1, 1.6 and 1.5 and it works on those devices too (so obviously the behaviour has been there all along).

WebView.setWebViewClient(new WebViewClient() {

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

         handler.proceed(); 

     }
    });

Upvotes: 2

vijay
vijay

Reputation: 1495

Add your manifest file

<uses-permission android:name="android.permission.INTERNET" />

When ever you accessing web content need to get internet permission then only it will load.

Upvotes: -3

KOTIOS
KOTIOS

Reputation: 11194

Try to use below attributes :

        webView = (WebView) findViewById(R.id.webView1);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);

Upvotes: 12

MZB
MZB

Reputation: 2111

One possibility here is a race condition.

You are loading https://www.facebook.com/ before setting up the WebViewClient, so there is a possibility that your implementation of OnReceivedSslError() will never get called if you get a quick enough response from facebook.

This would explain why it works for some people, not for others, and always works if the page is reloaded.

Also, I think you should just be returning false from shouldOverrideUrlLoading() if you want the page to load rather than attempting to reload the page - this might cause an infinite recursion / crash - possibly depending upon timing.

Upvotes: 1

Vamshi
Vamshi

Reputation: 1495

Try this

 WebView webview = (WebView)findViewById(R.id.webView); 
    Webview.setBackgroundColor(0);
    webview.getSettings().setJavaScriptEnabled(true); 
    webview.loadUrl("https://www.facebook.com");
    webview.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);

Upvotes: -5

CodingRat
CodingRat

Reputation: 1944

Add internet settings in your manifest.xml

<uses-permission android:name="android.permission.INTERNET" />

and check can you access internet on your device.

Upvotes: 8

Related Questions