我正在尝试在不提示用户的情况下安装证书。我知道这不是好的做法,但这就是 PM 想要的。
使用KeyChain.createInstallIntent()
,我可以通过调用 Android 来启动证书安装对话框startActivity
。但是,当我将意图传递给 时sendBroadcast
,什么也没有发生。也许出于安全原因该平台不支持此功能?
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) {