android - 使用生物识别 androidX 库 1.1.0 崩溃
问题描述
在我的应用程序中,我使用的是 androidX 生物识别支持库 1.1.0。在所有 Android 版本上,我的应用程序都崩溃了。这是我使用的代码片段
例外:
java.lang.IllegalStateException:必须从片段主机的主线程调用
在:
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);
}
解决方案
我已将代码移至 UI 线程
runOnUiThread(new Runnable() {
@Override
public void run() {
mBiometricPrompt.authenticate(promptInfo, cryptoObject);
}
});
推荐阅读
- angular - 为什么在使用单例类构建 Angular 包时出现错误?
- r - 可选参数与公式中的数据框冲突
- android - 注册后从数据库中检索数据的 JSON 错误
- jquery - 如何在 div 在响应式页面上保持 1:1.5 的比例时用图像填充 div
- datatables - 无法读取角度数据表中 null 的属性“替换”
- python - 如何将行添加到两个列表的数据框中
- ios - 在 iOS 中检测前台/后台代表的合适位置是什么?
- reactjs - 一旦我更新了 mobx 5,KonvaJs 示例就不起作用
- asp.net - oData v4 - 对相关一对多实体中的属性排序外部实体
- javascript - 在javascript中从数组中选择随机数量的元素