In my app, I'm using androidX biometric support library 1.1.0. On all Android versions, my app is crashing. Here is the code snippet that I have used
Exception:
java.lang.IllegalStateException: Must be called from main thread of fragment host
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);
}