2013-08-20 80 views
0

下面的代碼在4.0及以後的版本中成功安裝了CA,但它的工作效率低於4.0。任何機構都不知道我做錯了什麼。Android 4.0以下版本的CA證書安裝不起作用

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

定義「不起作用」 – njzk2

回答

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); 

感謝。