private static SSLSocketFactory trustAllHosts(HttpsURLConnection connection){
  SSLSocketFactory oldFactory=connection.getSSLSocketFactory();
  try {
    SSLContext sc=SSLContext.getInstance("TLS");
    sc.init(null,trustAllCerts,new java.security.SecureRandom());
    SSLSocketFactory newFactory=sc.getSocketFactory();
    connection.setSSLSocketFactory(newFactory);
  }
 catch (  Exception e) {
    Log.e(LOG_TAG,e.getMessage(),e);
  }
  return oldFactory;
}

private static SSLSocketFactory trustAllHosts ( HttpsURLConnection connection ) { SSLSocketFactory oldFactory = connection . getSSLSocketFactory ( ) ; try { SSLContext sc = SSLContext . getInstance ( "TLS" ) ; sc . init ( null , trustAllCerts , new java . security . SecureRandom ( ) ) ; SSLSocketFactory newFactory = sc . getSocketFactory ( ) ; connection . setSSLSocketFactory ( newFactory ) ; } catch ( Exception e ) { Log . e ( LOG_TAG , e . getMessage ( ) , e ) ; } return oldFactory ; }
this function will install a trust manager that will blindly trust all ssl certificates . the reason this code is being added is to enable developers to do development using self signed ssl certificates on their web server . the standard httpsurlconnection class will throw an exception on self signed certificates if this code is not run .
