I have an android app that call a secured website in a webview. The webview retrieve the certificate to give it to the website.
I have to use the KeyChain.choos
I'm not sure about the best way to resolve this problem, but here is what I did that worked fine for me.
I checked a boolean variable in the preferences, and if it returns false, I display the choosePrivateKeyAlias
window. If it returns true, I know that I have permission to retrieve the certificate directly, so there's no need to display the popup.
boolean isGranted = prefs.getBoolean("MY_CERT", false);
if(!isGranted) {
//Get cert and private key from internal android store
KeyChainAliasCallback keyChainAliasCallback = new KeyChainAliasCallback() {
@Override
public void alias(@Nullable String s) {
Log.d(TAG, "selected alias = " + s);
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
editor.putBoolean("MY_CERT", true);
editor.commit();
retriveCertsTask.execute();
}
};
KeyChain.choosePrivateKeyAlias(mActivity, keyChainAliasCallback, null, null, null, -1, CERT_ALIAS);
} else {
// Retrieve certs an private key
retriveCertsTask.execute();
}
}
Hope it helps...