[英]Crash using biometric androidX library 1.1.0
In my app, I'm using androidX biometric support library 1.1.0.在我的应用程序中,我使用的是 androidX 生物识别支持库 1.1.0。 On all Android versions, my app is crashing.
在所有 Android 版本上,我的应用程序都崩溃了。 Here is the code snippet that I have used
这是我使用的代码片段
Exception:例外:
java.lang.IllegalStateException: Must be called from main thread of fragment host
java.lang.IllegalStateException: 必须从片段宿主的主线程调用
In:在:
public boolean isFingerprintAuthAvailable(Context mContext) {
BiometricManager biometricManager = BiometricManager.from(mContext);
if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE) {
return false;
} else if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE) {
return false;
} else if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED) {
return false;
} else if (biometricManager.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
return true;
}
return false;
}
BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("fingerPrintTitle")
.setDescription("Description")
.setNegativeButtonText(""negative text")
.build();
if (isFingerprintAuthAvailable(mContext)) {
mBiometricPrompt.authenticate(promptInfo, cryptoObject);
}
I have moved the code to UI thread我已将代码移至 UI 线程
runOnUiThread(new Runnable() {
@Override
public void run() {
mBiometricPrompt.authenticate(promptInfo, cryptoObject);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.