16

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

Hareesh
  • 933
  • 3
  • 11
  • 22

9 Answers9

12

Try to use below attributes :

        webView = (WebView) findViewById(R.id.webView1);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
  • this worked ! http://stackoverflow.com/questions/7416096/android-webview-not-loading-https-url/28668862#28668862 – KOTIOS Feb 23 '15 at 07:38
  • 2
    This line: settings.setDomStorageEnabled(true); did the trick in my case. Thanks a lot. – Virthuss Dec 31 '15 at 09:41
8

Add internet settings in your manifest.xml

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

and check can you access internet on your device.

CodingRat
  • 1,934
  • 3
  • 23
  • 43
5

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

Alex
  • 201
  • 3
  • 10
3

You should remove this

super.OnReceiveSslError(view,handler,error);
Rami
  • 7,879
  • 12
  • 36
  • 66
Zahra.HY
  • 1,684
  • 1
  • 15
  • 25
2

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(); 

     }
    });
Suresh S
  • 49
  • 10
1

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.

MZB
  • 2,071
  • 3
  • 21
  • 38
  • The code listed by the OP above is similar to mine except for loading the URL *after* the WebView, WebViewClient have been properly set up - and I'm returning false from shouldOverrideUrlLoading(). – MZB May 20 '14 at 00:17
0

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
jakub.g
  • 38,512
  • 12
  • 92
  • 130
-3

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.

vijay
  • 1,475
  • 2
  • 16
  • 26
-5

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);
Vamshi
  • 1,495
  • 1
  • 15
  • 31