16

My application opens a web view to show HTML page, which is hosted with HTTPS contains one image(image coming from http). On some devices image is not showing but for all other devices its working fine. I checked with multiple devices like Nexus, Samsung s6/s4, Moto G2 and others. Only on Samsung S4/S6, nexus image is not showing. but for all other devices its working fine. Even i tried with WI-FI, data carrier, and multiple OS versions but no luck.

Please help to solve this.

some observations:-

1) On each device i am getting same warning :- [blocked] The page at 'page url' was loaded over HTTPS, but displayed insecure content from 'image source': this content should also be loaded over HTTPS.

2) same page if i am opening in web browser, working fine on all devices.

My Code

mWebView = (WebView) findViewById(R.id.m_web_view);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mainUrl = bean.getUrl();
    mWebView.loadUrl("javascript:window.location.reload( true )");
    mWebView.loadUrl(mainUrl);
    mWebView.setWebViewClient(new myWebClient());



    private class myWebClient extends WebViewClient {

    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
    //some code
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //some code
    }

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler,
            SslError error) {
        handler.proceed();
    }


}
Ajit Sharma
  • 201
  • 1
  • 2
  • 12
  • may be it is a problem of self signed certificate, can you check this http://stackoverflow.com/questions/5977977/does-the-web-view-on-android-support-ssl – Dickens A S Jul 20 '15 at 05:25

3 Answers3

62

Mixed content using HTTP and HTTPS on WebViews are disabled by default starting Lollipop. Is possible that is not working on devices with Lollipop? If this is the case, you can change the default WebView setting on Lollipop using:

webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);

Documentation here: http://developer.android.com/reference/android/webkit/WebSettings.html#setMixedContentMode(int)

Pollizzio
  • 1,023
  • 8
  • 11
3

Use the follwoing code. You can open https using the following code, extend the onReveivedSslError method of WebViewClient and proceed if any error occurred Here is an example

    WebView webview= (WebView) findViewById(R.id.my_webview);
    webview.setWebViewClient(new WebViewClient() {
     public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
     handler.proceed() ;
     }

}
Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
1

Actually it's a SSL property of webview so to handle this you will have to use following code.

engine = (WebView) findViewById(R.id.my_webview);
engine.setWebViewClient(new WebViewClient() {
 public void onReceivedSslError (WebView view, SslErrorHandler handler, SslError error) {
 handler.proceed() ;
 }
}

And in handler you can run webview image url easily.

Vishal Jain
  • 175
  • 2
  • 18