我是Android Fingerprint Listener的新手,并且自己学习。我面临取消指纹监听器的问题!
我已经建立了一个辅助课程,如下:
@RequiresApi(Build.VERSION_CODES.M)
class FingerprintHandler : FingerprintManager.AuthenticationCallback {
private var context: Context? = null
constructor(context: Context) {
this.context = context
}
fun startAuth(manager: FingerprintManager, context: Context, cancellationSignal: CancellationSignal) {
manager.authenticate(null, cancellationSignal, 0, this, null)
}
override fun onAuthenticationError(errorCode: Int, errString: CharSequence?) {
super.onAuthenticationError(errorCode, errString)
Toast.makeText(context!!, "Finger Print Authentication Error", Toast.LENGTH_SHORT).show()
}
override fun onAuthenticationSucceeded(result: FingerprintManager.AuthenticationResult?) {
super.onAuthenticationSucceeded(result)
Toast.makeText(context, context!!.resources.getString(R.string.success), Toast.LENGTH_SHORT).show()
}
override fun onAuthenticationHelp(helpCode: Int, helpString: CharSequence?) {
super.onAuthenticationHelp(helpCode, helpString)
}
override fun onAuthenticationFailed() {
super.onAuthenticationFailed()
Toast.makeText(context!!, "Finger Print Authentication Failed", Toast.LENGTH_SHORT).show()
}
}
在我的活动中,我有:
private var cancellationSignal: CancellationSignal? = null
override fun onPause() {
stopAuthentication()
fingerprintManager = null
super.onPause()
}
private fun stopAuthentication() {
if (cancellationSignal != null) {
cancellationSignal!!.cancel()
cancellationSignal!!.setOnCancelListener {
object : CancellationSignal.OnCancelListener {
override fun onCancel() {
Toast.makeText(applicationContext, "Signal Cancelled", Toast.LENGTH_SHORT).show()
}
}
}
}
}
主要问题是,每当我想停止监听器时,我都会调用stopAuthentication方法,但由于没有弹出Toast而无法停止它!
我仍然可以使用指纹扫描仪
我在做错什么,有人可以帮我!
我的测试设备是华为Mate 10 Oreo 8.0