Tuesday 21 May 2013

Self Signed SSL Web Service not working for phonegap application in android after the Export the Signed app

The solution for this problem, we need to handle like,

In the main Activity,we need to add blue color content like as,


import org.apache.cordova.DroidGap;
import android.os.Bundle;

public class MyPhoneGapActivity extends DroidGap {



@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

               super.init();
               MyWebViewClient webViewClient = new MyWebViewClient(this);
       webViewClient.setWebView(this.appView);
       this.appView.setWebViewClient(webViewClient);


super.loadUrl("file:///android_asset/www/index.html");
}
}




We need to create the MyWebViewClient class and make the onReceivedSslError method ,it calls handler.proceed();Then https service callling working fine.



import org.apache.cordova.CordovaWebViewClient;
import org.apache.cordova.api.CordovaInterface;

import android.net.http.SslError;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;

public class MyWebViewClient extends CordovaWebViewClient {

    public MyWebViewClient(CordovaInterface cordova) {
super(cordova);
// TODO Auto-generated constructor stub
}


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



Thank You

1 comment:

  1. Hi, thanks for this writeup. I have an issue with this code. This only works for the main PhoneGap web view but not for the https URLs opened in InAppBrowser. onReceivedSslError() is not called for InAppBrowser() as it's a different web view instance. Is there a way to make it work for InAppBrowser?

    ReplyDelete