Webview not able to load https url in android?
Asked Answered
D

9

17

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

Demarcate answered 22/8, 2013 at 10:21 Comment(4)
yes i added the INTERNET permissionDemarcate
It is worked for me. Please check your network permissions.Sigma
@Demarcate i have also tested.check ur internet availability in phone.Asdic
Update from 2016 if you came here from google: if this happens for you on Android 5+ ONLY and can't be explained in a rational way, this is due to a bug in chromium !Renter
T
12

Try to use below attributes :

        webView = (WebView) findViewById(R.id.webView1);
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
Thickset answered 23/2, 2015 at 7:38 Comment(2)
this worked ! #7416596Thickset
This line: settings.setDomStorageEnabled(true); did the trick in my case. Thanks a lot.Tiro
I
8

Add internet settings in your manifest.xml

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

and check can you access internet on your device.

Ite answered 22/8, 2013 at 10:31 Comment(0)
O
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

Octopus answered 18/12, 2015 at 8:22 Comment(0)
I
3

You should remove this

super.OnReceiveSslError(view,handler,error);
Infatuate answered 4/2, 2016 at 12:0 Comment(0)
E
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(); 

     }
    });
Expire answered 7/11, 2014 at 8:22 Comment(0)
D
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.

Detonator answered 15/5, 2014 at 17:39 Comment(1)
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().Detonator
R
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
Renter answered 12/12, 2016 at 11:22 Comment(0)
S
-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.

Sinclair answered 30/4, 2015 at 4:58 Comment(0)
C
-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);
Clydesdale answered 22/8, 2013 at 10:33 Comment(1)
... and why it should help?Nikolas

© 2022 - 2024 — McMap. All rights reserved.