title: how to install CA certificate programmatically on Android without user interaction
body: <p>I'm trying to install certificates without prompting the user.  I know this is not good practice, but that's what PM wants.</p>
  
  <p>Using <a href="http://developer.android.com/reference/android/security/KeyChain.html#createInstallIntent%28%29" rel="noreferrer"><code>KeyChain.createInstallIntent()</code></a>, I can get Android to launch the certificate installation dialog by calling <code>startActivity</code>.  However, when I pass the intent to <code>sendBroadcast</code>, nothing happens.  Maybe the platform doesn't support this for security reasons?</p>
  
  <pre><code>String CERT_FILE = Environment.getExternalStorageDirectory() + "/test/IAT.crt";
  Intent intent = KeyChain.createInstallIntent();
  try {
      FileInputStream certIs = new FileInputStream(CERT_FILE);
      byte [] cert = new byte[(int)certFile.length()];
      certIs.read(cert);
      X509Certificate x509 = X509Certificate.getInstance(cert);
      intent.putExtra(KeyChain.EXTRA_CERTIFICATE, x509.getEncoded()); 
      intent.putExtra(KeyChain.EXTRA_NAME, "IAT Cert");
      EapActivity.this.startActivityForResult(intent, 0);  // this works but shows UI
      EapActivity.this.sendBroadcast(intent);  // this doesn't install cert
  } catch (IOException e) {
  </code></pre>