infinum / Android-Goldfinger

Android library to simplify Biometric authentication implementation.
Apache License 2.0
653 stars 73 forks source link

handle onCancel? #71

Closed winnerawan closed 3 years ago

winnerawan commented 3 years ago

how to handle cancel ? Goldfinger.Callback() only has onResult and onError

domagojkorman commented 3 years ago

Hi @winnerawan ,

There are 2 different cancel types. First is if you manually call cancel method, second is if the User himself presses on the Cancel button.

In the first scenario, nothing will be triggered on the callback because if you cancel the authentication yourself, you don't want potential callback being triggered because it could leak and cause a crash while you are navigating to another screen.

In the second scenario, when the User cancels the authentication himself, you will get a callback to onResult with specific USER_CANCELED reason which can be found here.

I also suggest looking at other enumerations to see which other cases are covered.

winnerawan commented 3 years ago

Thanks for reply @domagojkorman i think it's the second scenario, when dialog pop up shown, user choose cancel. below code doesn't work, i dont get toast message

if (result.reason() == Goldfinger.Reason.CANCELED) {
   Toast.makeText(getBaseActivity(), "CANCEL", Toast.LENGTH_SHORT).show();
}
domagojkorman commented 3 years ago

Did you try using Goldfinger.Reason.USER_CANCELED? The exact enum that I linked in my previous response - here

winnerawan commented 3 years ago

Actually it's Goldfinger.Reason.NEGATIVE_BUTTON i think i need sleep and read it again, sorry, my bad. case closed