Webview not able to load https url in android?

非 Y 不嫁゛ 提交于 2019-12-30 00:58:06

问题


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.

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


回答1:


Try to use below attributes :

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



回答2:


Add internet settings in your manifest.xml

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

and check can you access internet on your device.




回答3:


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




回答4:


You should remove this

super.OnReceiveSslError(view,handler,error);



回答5:


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

     }
    });



回答6:


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.




回答7:


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



回答8:


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.




回答9:


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


来源:https://stackoverflow.com/questions/18377769/webview-not-able-to-load-https-url-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!