Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For non-system app developers - the simple answer is it can not be done without user interaction.</p> <p>For System App developers, I found the following solution, NB you must run the app with the system user id and sign the app with the system key or the service will reject your attempts to install the certificate.</p> <p><strong>Step 1</strong> - <em>Create interface</em></p> <p>Create a new package in your project: <strong><em>android.security</em></strong>, then copy <a href="https://github.com/android/platform_frameworks_base/blob/master/keystore/java/android/security/IKeyChainService.aidl" rel="nofollow">IKeyChainService.aidl</a> into this package.</p> <p><strong>Step 2</strong> - <em>Bind to service and install certificate</em></p> <p>The Activity gives an example of how to install a CA certificate:</p> <pre><code>public class KeyChainTest extends Activity { private final Object mServiceLock = new Object(); private IKeyChainService mService; private boolean mIsBoundService =false; private ServiceConnection mServiceConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { synchronized (mServiceLock) { mService = IKeyChainService.Stub.asInterface(service); mServiceLock.notifyAll(); try { byte[] result = YOUR_CA_CERT_AS_BYTE_ARRAY //The next line actually installs the certificate mService.installCaCertificate(result); } catch (Exception e) { //EXception handling goes here } } } @Override public void onServiceDisconnected(ComponentName name) { synchronized (mServiceLock) { mService = null; } } }; private void bindService() { mIsBoundService = bindService(new Intent(IKeyChainService.class.getName()), mServiceConnection, Context.BIND_AUTO_CREATE); } private void unbindServices() { if (mIsBoundService) { unbindService(mServiceConnection); mIsBoundService = false; } } @Override public void onDestroy () { unbindServices(); } @Override protected void onStart() { super.onStart(); // Bind to KeyChainService bindService(); } } </code></pre> <p>I hope this helps someone - it took me a long time to work it out :)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload