Android基于compose进行指纹验证

232 阅读1分钟

基于compose进行指纹验证

点击按钮进行验证

Button(onClick = {
   var passed = false
   val biometic = BiometricPrompt.Builder(applicationContext)
        .setTitle("使用指纹解锁App")
        .setSubtitle("证明你是手机的主人")
        .setNegativeButton("取消验证", mainExecutor
        ) { dialog, which -> Log.e(TAG, "onCreate: click negative buttton", ) }
        .build()
    biometic.authenticate(CancellationSignal(), mainExecutor, 
        object:AuthenticationCallback(){
            override fun onAuthenticationFailed() {
                super.onAuthenticationFailed()
                Log.d(TAG, "onAuthenticationFailed: ")
                passed = false
            }
            override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult?) {
                super.onAuthenticationSucceeded(result)
                Log.d(TAG, "onAuthenticationSucceeded: ")
                passed = true
            }
        }
    )
}) {
    Text(text = "指纹解锁")
}