Example usage for android.security KeyChain choosePrivateKeyAlias

List of usage examples for android.security KeyChain choosePrivateKeyAlias

Introduction

In this page you can find the example usage for android.security KeyChain choosePrivateKeyAlias.

Prototype

public static void choosePrivateKeyAlias(@NonNull Activity activity, @NonNull KeyChainAliasCallback response,
        @Nullable @KeyProperties.KeyAlgorithmEnum String[] keyTypes, @Nullable Principal[] issuers,
        @Nullable Uri uri, @Nullable String alias) 

Source Link

Document

Launches an Activity for the user to select the alias for a private key and certificate pair for authentication.

Usage

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

/**
 * Selects a private/public key pair to uninstall, using the system dialog to choose
 * an alias.//from  www.  java2 s  .  c o  m
 *
 * Once the alias is chosen and deleted, a {@link Toast} shows status- success or failure.
 */
@TargetApi(Build.VERSION_CODES.N)
private void choosePrivateKeyForRemoval() {
    KeyChain.choosePrivateKeyAlias(getActivity(), new KeyChainAliasCallback() {
        @Override
        public void alias(String alias) {
            if (alias == null) {
                // No value was chosen.
                return;
            }

            final boolean removed = mDevicePolicyManager.removeKeyPair(mAdminComponentName, alias);

            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (removed) {
                        showToast(R.string.remove_keypair_successfully);
                    } else {
                        showToast(R.string.remove_keypair_fail);
                    }
                }
            });
        }
    }, /* keyTypes[] */ null, /* issuers[] */ null, /* uri */ null, /* alias */ null);
}