Example usage for android.security KeyChainAliasCallback KeyChainAliasCallback

List of usage examples for android.security KeyChainAliasCallback KeyChainAliasCallback

Introduction

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

Prototype

KeyChainAliasCallback

Source Link

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.// w w w . j a  v a  2s . c om
 *
 * 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);
}