Created
February 19, 2020 17:59
-
-
Save isaidamier/4ca263dd8e5b60fe585ae9d63ee3592f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
... | |
private lateinit var biometricPrompt: BiometricPrompt | |
... | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
... | |
biometricPrompt = createBiometricPrompt() | |
... | |
} | |
private fun createBiometricPrompt(): BiometricPrompt { | |
val executor = ContextCompat.getMainExecutor(this) | |
val callback = object : BiometricPrompt.AuthenticationCallback() { | |
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { | |
super.onAuthenticationError(errorCode, errString) | |
Log.d(TAG, "$errorCode :: $errString") | |
} | |
override fun onAuthenticationFailed() { | |
super.onAuthenticationFailed() | |
Log.d(TAG, "Authentication failed for an unknown reason") | |
} | |
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { | |
super.onAuthenticationSucceeded(result) | |
Log.d(TAG, "Authentication was successful") | |
processData(result.cryptoObject) | |
} | |
} | |
//The API requires the client/Activity context for displaying the prompt | |
val biometricPrompt = BiometricPrompt(this, executor, callback) | |
return biometricPrompt | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment