下面的代码在 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();
}
}