Skip to content

Instantly share code, notes, and snippets.

@isaidamier
Created October 5, 2020 21:36
Show Gist options
  • Save isaidamier/288509176d01714e08fc10471ed85d84 to your computer and use it in GitHub Desktop.
Save isaidamier/288509176d01714e08fc10471ed85d84 to your computer and use it in GitHub Desktop.
binding.useBiometrics.setOnClickListener {
showBiometricPromptForEncryption()
}
....
private fun showBiometricPromptForEncryption() {
val canAuthenticate = BiometricManager.from(applicationContext).canAuthenticate()
if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) {
val secretKeyName = SECRET_KEY_NAME
cryptographyManager = CryptographyManager()
val cipher = cryptographyManager.getInitializedCipherForEncryption(secretKeyName)
val biometricPrompt =
BiometricPromptUtils.createBiometricPrompt(this, ::encryptAndStoreServerToken)
val promptInfo = BiometricPromptUtils.createPromptInfo(this)
biometricPrompt.authenticate(promptInfo, BiometricPrompt.CryptoObject(cipher))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment