Android BiometricPrompt 已完成指纹识别,但 onAuthenicationSucceeded 不起作用。
我用了androidx
示例:Log.i("finger", "onAuthenticationSucceeded")
不输出
复制此代码:https ://developer.android.com/training/sign-in/biometric-auth#kotlin
主要活动:
private fun showBiometricPrompt() {
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Biometric login for my app")
.setSubtitle("Log in using your biometric credential")
.setNegativeButtonText("Cancel")
.build()
Log.i("finger", "o")
val biometricPrompt = BiometricPrompt(this, executor,
object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int,
errString: CharSequence) {
Log.i("finger", "onAuthenticationError")
super.onAuthenticationError(errorCode, errString)
Toast.makeText(applicationContext,
"Authentication error: $errString", Toast.LENGTH_SHORT)
.show()
}
override fun onAuthenticationSucceeded(
result: BiometricPrompt.AuthenticationResult) {
super.onAuthenticationSucceeded(result)
Log.i("finger", "onAuthenticationSucceeded")
val authenticatedCryptoObject: BiometricPrompt.CryptoObject? =
result.getCryptoObject()
// User has verified the signature, cipher, or message
// authentication code (MAC) associated with the crypto object,
// so you can use it in your app's crypto-driven workflows.
}
override fun onAuthenticationFailed() {
Log.i("finger", "onAuthenticationFailed")
super.onAuthenticationFailed()
Toast.makeText(applicationContext, "Authentication failed",
Toast.LENGTH_SHORT)
.show()
}
})
// Displays the "log in" prompt.
biometricPrompt.authenticate(promptInfo)
}
}
来自当前 android studio 的日志
2019-11-27 19:45:22.348 11633-11633/? I/e.myapplicatio: Late-enabling -Xcheck:jni
2019-11-27 19:45:23.124 11633-11633/com.example.myapplication W/e.myapplicatio: JIT profile information will not be recorded: profile file does not exits.
2019-11-27 19:45:23.127 11633-11633/com.example.myapplication I/chatty: uid=10263(com.example.myapplication) identical 10 lines
2019-11-27 19:45:23.127 11633-11633/com.example.myapplication W/e.myapplicatio: JIT profile information will not be recorded: profile file does not exits.
2019-11-27 19:45:23.197 11633-11633/com.example.myapplication I/InstantRun: starting instant run server: is main process
2019-11-27 19:45:23.363 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
2019-11-27 19:45:23.363 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
2019-11-27 19:45:23.363 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
2019-11-27 19:45:23.363 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
2019-11-27 19:45:23.363 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
2019-11-27 19:45:23.421 11633-11633/com.example.myapplication D/PhoneWindow: windowLightStatusBar : false, disable View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
2019-11-27 19:45:23.489 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden method Landroid/view/View;->getAccessibilityDelegate()Landroid/view/View$AccessibilityDelegate; (light greylist, linking)
2019-11-27 19:45:23.593 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-11-27 19:45:23.594 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-11-27 19:45:23.610 11633-11633/com.example.myapplication W/e.myapplicatio: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2019-11-27 19:45:23.726 11633-11633/com.example.myapplication I/App can authenticate using biometrics.: OK
2019-11-27 19:45:23.760 11633-11633/com.example.myapplication D/OpenGLRenderer: Skia GL Pipeline
2019-11-27 19:45:23.835 11633-11633/com.example.myapplication I/TouchFilterInputStageHelper: [needTouchEventFilter] Displayid : 0
2019-11-27 19:45:23.841 11633-11633/com.example.myapplication D/BezellessGripSuppressionFilter: getdisplaysize, x : 1440 y : 2880
2019-11-27 19:45:23.924 11633-11733/com.example.myapplication I/Adreno: QUALCOMM build : 6aca7ed, I9a84ac9597
Build Date : 08/23/19
OpenGL ES Shader Compiler Version: EV031.25.03.07
Local Branch :
Remote Branch : refs/tags/AU_LINUX_ANDROID_LA.UM.7.5.2.R1.09.00.00.538.032
Remote Branch : NONE
Reconstruct Branch : NOTHING
2019-11-27 19:45:23.924 11633-11733/com.example.myapplication I/Adreno: Build Config : S L 6.0.7 AArch64
2019-11-27 19:45:23.924 11633-11733/com.example.myapplication D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8996.so from current namespace instead of sphal namespace.
2019-11-27 19:45:23.938 11633-11733/com.example.myapplication I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
2019-11-27 19:45:23.980 11633-11733/com.example.myapplication I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-11-27 19:45:23.982 11633-11733/com.example.myapplication I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-11-27 19:45:23.983 11633-11733/com.example.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
2019-11-27 19:45:23.983 11633-11733/com.example.myapplication D/OpenGLRenderer: Swap behavior 2
2019-11-27 19:45:24.008 11633-11733/com.example.myapplication D/vndksupport: Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
2019-11-27 19:45:24.009 11633-11733/com.example.myapplication D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8996.so from current namespace instead of sphal namespace.
2019-11-27 19:45:24.178 11633-11633/com.example.myapplication I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@64768ba time:68742526
2019-11-27 19:45:26.690 11633-11633/com.example.myapplication I/ViewRootImpl: ViewRoot's Touch Event : ACTION_DOWN
2019-11-27 19:45:26.761 11633-11633/com.example.myapplication I/ViewRootImpl: ViewRoot's Touch Event : ACTION_UP