android调用系统弹出窗口后Activity无法操作

Dawn_sun 发布于 2014/07/22 11:28
阅读 454
收藏 0

调用 KeyChain.choosePrivateKeyAlias(....)后会弹出一个选择已经安装的证书窗口,不选择证书,点击Deny可以直接退出,Activity正常,点击Allow,获取到证书,选择窗口消失,但屏幕就一直是灰的……有没有大神知道怎么办?

附代码:

public class ChooseCertificate extends Activity{

 String SavedAlias = "";
 private static final String TAG = "ChooseCertificate.CLASS";

 public Handler mHandler = new Handler(Looper.getMainLooper());

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  getCertificates("TEST");
 }
 
 public void run() {
  mHandler.post(new Runnable() {
   public void run() {
    new AliasLoader().execute();
   }
  });
 }

 public class AliasLoader extends AsyncTask<Void, Void, X509Certificate[]> {
  X509Certificate[] chain = null;

  @Override
  protected X509Certificate[] doInBackground(Void... params) {
//   android.os.Debug.waitForDebugger();

   if (!SavedAlias.isEmpty()) {
    try {
     chain = KeyChain.getCertificateChain(getApplicationContext(), SavedAlias);
    } catch (Exception e) {
     Log.e(TAG, e.getMessage());
    }
   } else {
    this.cancel(true);
   }

   return chain;
  }

  @Override
  protected void onPostExecute(X509Certificate[] chain) {

   if (chain != null) {
    CertificateInfo certInfo = new CertificateInfo(chain[0]);
    System.out.println("Chain: -- > \n使用者:" + certInfo.getUserInfo() + "\npublicKer:" + certInfo.getpublicKeyStringMD5());
    Toast.makeText(getApplicationContext(),"YAY, Certificate is not empty", Toast.LENGTH_LONG).show();
   } else {
    Toast.makeText(getApplicationContext(), "Certificate is Empty",Toast.LENGTH_LONG).show();
   }
   
  }
 }

 public void getCertificates(String Host) {
  KeyChainAliasCallback callBack = new KeyChainAliasCallback() {

   @Override
   public void alias(String alias) {
    if (alias != null) {
     Looper.prepare();
     saveAlias(alias);
     run();
     Looper.loop();
    }
   }
  };

  KeyChain.choosePrivateKeyAlias(this, callBack, new String[] {"PKCS12"}, // List of acceptable key types. null for any
    null, // issuer, null for any
    Host, // host name of server requesting the cert, null if  unavailable
    -1, // port of server requesting the cert, -1 if unavailable
    null); // alias to preselect, null if unavailable
 }

 public void saveAlias(String alias) {
  SavedAlias = alias;
 }
}

加载中
0
logan676
logan676
你的手机可能不是原生系统吧?你涉及到的操作是读取安装到系统中的证书的,android为了安全起见,需要设置一个进入手机是的密码,可以是手势锁或者密码。如果你安装证书的时候,没有提示你设置密码,说明你的手机是定制过的系统,我用的小米手机也这样。使用Nexus6(原生系统)就可以了。
返回顶部
顶部