下面的代码在4.0及更高版本上成功安装了CA,但是它在4.0以下不起作用。任何机构都知道我做错了什么。
private void showCAInstallationDialog() {
try {
InputStream caInputStream = getResources()
.openRawResource(R.raw.ca);
if (caInputStream != null) {
byte[] result;
result = IOUtils.toByteArray(caInputStream);
// The next line actually installs the certificate
Intent intent = new Intent("android.credentials.INSTALL");
intent.putExtra("name", getString(R.string.app_name) + " CA ");
intent.putExtra("CERT", result);
startActivityForResult(intent, CA_CERTIFICATE_ADDED);
} else {
Utility.logError(getSimpleName(),
"Error occurred while reading CA");
}
} catch (IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
您可以尝试以下代码 - (如果您仍需要答案)
java.security.cert.X509Certificate cert;
byte [] certArray = //conver this "cer" to PEM using PEMWriter (use bouncy Castle library "bcprov-jdk15-140.jar")
Intent intent = null;
intent = new Intent("android.credentials.SYSTEM_INSTALL");
intent.setClassName("com.android.settings","com.android.settings.CredentialInstaller");
intent.putExtra("CACERT_" + "nameOfCert" + "CA", certArray);
mContext.startActivityForResult(intent);
感谢。