/** Creates the Activity and registers a MemorizingTrustManager. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.mtmexample); // set up gui elements findViewById(R.id.connect).setOnClickListener(this); content = (TextView) findViewById(R.id.content); urlinput = (EditText) findViewById(R.id.url); verifyhost = (CheckBox) findViewById(R.id.verifyhost); // register handler for background thread hdlr = new Handler(); // Here, the MemorizingTrustManager is activated for HTTPS try { // set location of the keystore MemorizingTrustManager.setKeyStoreFile("private", "sslkeys.bks"); // register MemorizingTrustManager for HTTPS SSLContext sc = SSLContext.getInstance("TLS"); sc.init(null, MemorizingTrustManager.getInstanceList(this), new java.security.SecureRandom()); HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); defaultverifier = HttpsURLConnection.getDefaultHostnameVerifier(); // disable redirects to reduce possible confusion HttpsURLConnection.setFollowRedirects(false); } catch (Exception e) { e.printStackTrace(); } }