3

I need to load a https url in android webview but it gets loaded with white screen.

I have also handled public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) but still getting white screen on getting loaded with the url but there are no exceptions in the logcat.

below is my code

public class MainActivity extends Activity { 
private static final String URL = "https://someurl";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    WebView myWebView = (WebView)findViewById(R.id.webview);

    WebSettings settings = myWebView.getSettings();

    settings.setJavaScriptEnabled(true);

    settings.setDomStorageEnabled(true);

    myWebView.loadUrl(URL);



    myWebView.setWebViewClient(new MyWebViewClient());


}


private class MyWebViewClient extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (Uri.parse(url).getHost().equals(URL)) {

            return false;
        }
        Activity that handles URLs
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        startActivity(intent);
        return true;
    }

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


        handler.proceed();
    }
}

}

Looking forward to your reply.

thanks

Mukunda
  • 1,593
  • 3
  • 26
  • 45
  • You need a verified and trusted SSL Certificate, also notice that there's something called mid-Certificate or something like that if your SSL issuer is a cheap one like GoDaddy for instance, this Middle Certificate if missing doesn't give errors on PC Browsers but it does on Mobile Browsers, There's a work around for opening untrusted certificates on mobile browsers but it's really complicated to setup – Shehabic Jan 12 '13 at 08:35
  • @Shehabix thanks. can you let us know what is workaround for this error. – Mukunda Jan 12 '13 at 08:46
  • have you tried and load a regular http url, and see if the WebView still is white? – TouchBoarder Jan 12 '13 at 09:46
  • @hsigmond yes regular http loads perfectly. – Mukunda Jan 12 '13 at 10:47

3 Answers3

1

handler.proceed(); should make the WebView load the https url, have you tried and load a regular http url,and see if the WebView still is white.

There is a bug in Android rendering the WebView white at times.

Try to disable hardware acceleration on the WebView, set android:layerType="software" attribute on the webview in the .xml layout resource.

<WebView
    android:id="@+id/webviev"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    android:layerType="software" />
TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
1

There are certain SSL certificates that were not supported in Android 2.2, you can try and check to load it in native browser, if it works on browser then it might be supported. If it is not supported, you have atleast following two options

  1. To change the SSL certificate provider assuming you have admin rights to the website
  2. To implement a work around like SSL not working on Android 2.2 (only in 2.3)

Please check whether the SSL is supported on the other Android versions as well.

Community
  • 1
  • 1
Meghal Shah
  • 405
  • 2
  • 11
0
mWebview.setWebViewClient(new WebViewClient() {


        @Override
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            super.onReceivedSslError(view, handler, error);
           //Error happens here and returns an empty page.
        }

On 2.3 devices there is a problem with the certification validation. It might be valid, but when in incorrect order, it fails.

you can call handler.proceed(); But I don't recommend it ! As it breaks required validation.

Christophe Smet
  • 850
  • 10
  • 11