Java Code Examples for androidx.biometric.BiometricPrompt#authenticate()

The following examples show how to use androidx.biometric.BiometricPrompt#authenticate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From android-biometricprompt with Apache License 2.0 6 votes vote down vote up
private void showBiometricPrompt(Signature signature) {
    BiometricPrompt.AuthenticationCallback authenticationCallback = getAuthenticationCallback();
    BiometricPrompt mBiometricPrompt = new BiometricPrompt(this, getMainThreadExecutor(), authenticationCallback);

    // Set prompt info
    BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
            .setDescription("Description")
            .setTitle("Title")
            .setSubtitle("Subtitle")
            .setNegativeButtonText("Cancel")
            .build();

    // Show biometric prompt
    if (signature != null) {
        Log.i(TAG, "Show biometric prompt");
        mBiometricPrompt.authenticate(promptInfo, new BiometricPrompt.CryptoObject(signature));
    }
}
 
Example 2
Source File: AuthActivity.java    From Aegis with GNU General Public License v3.0 6 votes vote down vote up
public void showBiometricPrompt() {
    Cipher cipher;
    try {
        cipher = _bioSlot.createDecryptCipher(_bioKey);
    } catch (SlotException e) {
        e.printStackTrace();
        Dialogs.showErrorDialog(this, R.string.biometric_init_error, e);
        return;
    }

    BiometricPrompt.CryptoObject cryptoObj = new BiometricPrompt.CryptoObject(cipher);
    _bioPrompt = new BiometricPrompt(this, new UiThreadExecutor(), new BiometricPromptListener());

    BiometricPrompt.PromptInfo info = new BiometricPrompt.PromptInfo.Builder()
            .setTitle(getString(R.string.authentication))
            .setNegativeButtonText(getString(android.R.string.cancel))
            .setConfirmationRequired(false)
            .build();
    _bioPrompt.authenticate(info, cryptoObj);
}
 
Example 3
Source File: KeychainModule.java    From react-native-keychain with MIT License 6 votes vote down vote up
/** trigger interactive authentication. */
public void startAuthentication() {
  final FragmentActivity activity = (FragmentActivity) getCurrentActivity();
  if (null == activity) throw new NullPointerException("Not assigned current activity");

  // code can be executed only from MAIN thread
  if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
    activity.runOnUiThread(this::startAuthentication);
    waitResult();
    return;
  }

  final BiometricPrompt prompt = new BiometricPrompt(activity, executor, this);

  prompt.authenticate(this.promptInfo);
}
 
Example 4
Source File: SplashActivity.java    From Rucky with GNU General Public License v3.0 5 votes vote down vote up
public void biometric() {
    Executor executor = ContextCompat.getMainExecutor(this);
    BiometricPrompt biometricPrompt = new BiometricPrompt(this, executor, new BiometricPrompt.AuthenticationCallback() {
        @Override
        public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
            super.onAuthenticationError(errorCode, errString);
            finishAffinity();
            System.exit(0);
        }

        @Override
        public void onAuthenticationSucceeded(
                @NonNull BiometricPrompt.AuthenticationResult result) {
            super.onAuthenticationSucceeded(result);
            splash();
            getKey();
        }

        @Override
        public void onAuthenticationFailed() {
            super.onAuthenticationFailed();
            finishAffinity();
            System.exit(0);
        }
    });

    BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
            .setTitle(getResources().getString(R.string.unlock))
            .setSubtitle(getResources().getString(R.string.auth))
            .setConfirmationRequired(false)
            .setDeviceCredentialAllowed(true)
            .build();
    biometricPrompt.authenticate(promptInfo);

}