Reputation: 4713
I am using new BiometricPrompt in my Android Application from the below literary
implementation 'androidx.biometric:biometric:1.0.0-rc01'
I am able to successfully show the BiometicPrompt when an activity is loaded.
My issue is if I keep the Prompt ideal for 30-60 seconds or if I change the app to background or if i lock and unlock the screen while Prompt is showing when application reappears again BiometricPrompt is getting dismissed/not showing. I cannot determine whether the issue is with my executor please help. Below is my code
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Executor executor = Executors.newFixedThreadPool(2);
final BiometricPrompt biometricPrompt = new BiometricPrompt(this,
executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
super.onAuthenticationError(errorCode, errString);
}
@Override
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
navigateHome();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
});
final BiometricPrompt.PromptInfo promptInfo = new BiometricPrompt.PromptInfo.Builder()
.setTitle("Authenticate")
.setSubtitle("Unlock with your fingerprint")
.setNegativeButtonText("Cancel")
.build();
biometricPrompt.authenticate(promptInfo);
}
Updates on 13/02/2019
I updated to
implementation 'androidx.biometric:biometric:1.0.1'
and changed executor like below
Executor executor = ContextCompat.getMainExecutor(this);
Most of the issues are solved now except in Oneplus Device with indisplay finger print scanner(6T and above models). On providing an incorrect finger scan (on first time itself) the Prompt is calling onAuthenticationFailed() instead of onAuthenticationError(..)
Upvotes: 1
Views: 4406
Reputation: 81
As mentioned in the answers there's an intentional behavior by biometric prompt to not re prompt once in the background.
There is a workaround on this however, in your Activity use the WindowFocusChanged
@Override
public void onWindowFocusChanged(boolean hasFocus){
if(hasFocus){
biometricPromptFunction();
}
}
Basically when the app comes back from the foreground the focus is on the current Activity and it launches the Biometric prompt. Keep in mind that it will keep prompting even if it's cancelled or dismissed. To avoid this you'll need to keep a counter that increments when the windowFocus is changed and reset on the onResume Function.
Upvotes: 4
Reputation: 984
When the task stack switches (user goes to different app or home screen), or when the device goes to keyguard/screen-off, BiometricPrompt goes away. It's intentional behavior that authentication is not restored, since it's possible for the user to resume the app and already forgot the context.
Upvotes: 0
Reputation: 58487
That is according to design. Apps are not supposed to wait for biometric authentication indefinitely. How long the timeout is may vary between different devices.
When the timeout occurs I would expect you to get a call to onAuthenticationError
with BiometricConstants.BIOMETRIC_ERROR_TIMEOUT
as the error code.
I have no idea why Google has chosen no to expose that constant through the BiometricManager
. However, any call to onAuthenticationError
should be treated as an unrecoverable error and as the authentication having ended.
Upvotes: 2