Dave Nottage 563 Posted May 23, 2023 It's in Portuguese, but there's this: Also this: https://github.com/DeveloppeurPascal/Delphi-samples/tree/main/FireMonkey-Samples/017-TBiometricAuth Share this post Link to post
stacker_liew 5 Posted May 23, 2023 I created a demo app, but it won't work. BiometricAuthDemo.7z Share this post Link to post
Dave Nottage 563 Posted May 23, 2023 4 minutes ago, stacker_liew said: I created a demo app, but it won't work. You do not have the Biometric Authorization Service option checked in the Entitlement List in Project Options Share this post Link to post
stacker_liew 5 Posted May 23, 2023 1 minute ago, Dave Nottage said: You do not have the Biometric Authorization Service option checked in the Entitlement List in Project Options OK, thanks. Share this post Link to post
stacker_liew 5 Posted May 23, 2023 4 minutes ago, stacker_liew said: OK, thanks. I checked the Biometric Authorization Service, still won't work. Share this post Link to post
Dave Nottage 563 Posted May 23, 2023 1 minute ago, stacker_liew said: still won't work. You'll need to me more specific about what "won't work" means. Please also note that only Android 10 or higher is supported Share this post Link to post
stacker_liew 5 Posted May 23, 2023 (edited) 1 minute ago, Dave Nottage said: You'll need to me more specific about what "won't work" means. Please also note that only Android 10 or higher is supported It should display the request permission dialog, but it won't. I'm using Android 12. Edited May 23, 2023 by stacker_liew Share this post Link to post
Dave Nottage 563 Posted May 23, 2023 1 minute ago, stacker_liew said: It should display the request permission dialog No error messages? Can you provide a reproducible example that does not have dependencies on TFrameStand or other 3rd party code? Share this post Link to post
stacker_liew 5 Posted May 23, 2023 1 minute ago, Dave Nottage said: No error messages? Can you provide a reproducible example that does not have dependencies on TFrameStand or other 3rd party code? Wait...I create another one which without third party component. Share this post Link to post
stacker_liew 5 Posted May 23, 2023 31 minutes ago, stacker_liew said: Wait...I create another one which without third party component. This is the new one without third party components. NewBiometricAuthDemo.7z Share this post Link to post
programmerdelphi2k 237 Posted May 23, 2023 (edited) @stacker_liew you need this to "work": tested in Android 11 (API 30)... (using default targetSdkVersion = 32 by Delphi) Quote Needs 2 permissions involved: USE_BIOMETRIC = new IDEs USE_FINGERPRINT = if older (deprecated in new IDEs) Project->Options: Entitlement List -> Biometric Authorization Service Permissions: Use Biometric (new IDE) Use Fingerprint (older IDE) TBiometricAuth component: mandatory choices: BiometricAuth1.PromptDescription BiometricAuth1.PromptTitle BiometricAuth1.BiometricStrengths Request/Rationale events from request permissions! Biometric events if: success or failed! PermissionBiometric: TArray<string>; //... OnCreate Form: -------------- PermissionBiometric := ['android.permission.USE_BIOMETRIC']; // , 'android.permission.USE_FINGERPRINT']; // NOT mandatory == FIXED! BiometricAuth1.PromptDescription := 'my description'; // mandatory BiometricAuth1.PromptTitle := 'my title'; // mandatory BiometricAuth1.BiometricStrengths := [ TBiometricStrength.DeviceCredential { , others... }]; // mandatory //... procedure TForm1.BiometricPermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); begin // 2 permissions involved: USE_BIOMETRIC + USE_FINGERPRINT if (Length(AGrantResults) = 1 {2}) and (AGrantResults[0] = TPermissionStatus.Granted) then // and (AGrantResults[1] = TPermissionStatus.Granted) then BiometricAuth1.Authenticate; //... end; //... procedure TForm1.Button1Click(Sender: TObject); begin PermissionsService.RequestPermissions( { } PermissionBiometric, { } BiometricPermissionRequestResult, { } DisplayRationale); end; // ... procedure TForm1.BiometricAuth1AuthenticateFail(Sender: TObject; const FailReason: TBiometricFailReason; const ResultMessage: string); begin TDialogService.ShowMessage('Failed!'); end; procedure TForm1.BiometricAuth1AuthenticateSuccess(Sender: TObject); begin TDialogService.ShowMessage('Successed!'); end; Edited May 23, 2023 by programmerdelphi2k Share this post Link to post
stacker_liew 5 Posted May 23, 2023 (edited) 2 hours ago, programmerdelphi2k said: @stacker_liew you need this to "work": tested in Android 11 (API 30)... (using default targetSdkVersion = 32 by Delphi) PermissionBiometric: TArray<string>; //... OnCreate Form: -------------- PermissionBiometric := ['android.permission.USE_BIOMETRIC']; // , 'android.permission.USE_FINGERPRINT']; // mandatory BiometricAuth1.PromptDescription := 'my description'; // mandatory BiometricAuth1.PromptTitle := 'my title'; // mandatory BiometricAuth1.BiometricStrengths := [ TBiometricStrength.DeviceCredential { , others... }]; // mandatory //... procedure TForm1.BiometricPermissionRequestResult(Sender: TObject; const APermissions: TClassicStringDynArray; const AGrantResults: TClassicPermissionStatusDynArray); begin // 2 permissions involved: USE_BIOMETRIC + USE_FINGERPRINT if (Length(AGrantResults) = 1 {2}) and (AGrantResults[0] = TPermissionStatus.Granted) then // and (AGrantResults[1] = TPermissionStatus.Granted) then BiometricAuth1.Authenticate; //... end; //... procedure TForm1.Button1Click(Sender: TObject); begin PermissionsService.RequestPermissions( { } PermissionBiometric, { } BiometricPermissionRequestResult, { } DisplayRationale); end; // ... procedure TForm1.BiometricAuth1AuthenticateFail(Sender: TObject; const FailReason: TBiometricFailReason; const ResultMessage: string); begin TDialogService.ShowMessage('Failed!'); end; procedure TForm1.BiometricAuth1AuthenticateSuccess(Sender: TObject); begin TDialogService.ShowMessage('Successed!'); end; I followed your instruction, still won't work. Here is the source. Edited May 23, 2023 by stacker_liew Upgrade new file Share this post Link to post
stacker_liew 5 Posted May 23, 2023 This is new one. NewBiometricAuthDemo.7z Share this post Link to post
programmerdelphi2k 237 Posted May 23, 2023 @stacker_liew I just to say: it works for me in Android 11 / RAD 11.3 FMX 64bits project! FMX_BioMetric_usage.7z Share this post Link to post
stacker_liew 5 Posted May 23, 2023 17 minutes ago, programmerdelphi2k said: @stacker_liew I just to say: it works for me in Android 11 / RAD 11.3 FMX 64bits project! FMX_BioMetric_usage.7z I'm using Android 12, it skip the Request Permission section. RAD 11.3.1 FMX 64 bits. Share this post Link to post
Dave Nottage 563 Posted May 23, 2023 3 hours ago, programmerdelphi2k said: you need this to "work" Incorrect. USE_BIOMETRIC needs to be included in the permissions, but only dangerous permissions need to be explicitly requested at runtime. 7 hours ago, stacker_liew said: This is the new one without third party components. You're also missing the Use Biometric permission in the Permissions section of Project Options. Sorry, I should have checked for that earlier. 1 Share this post Link to post
stacker_liew 5 Posted May 23, 2023 I know what happen, I forget to tick two permissions in project option. Share this post Link to post
programmerdelphi2k 237 Posted May 23, 2023 (edited) 7 minutes ago, stacker_liew said: , it skip the Request Permission section. better read more about it https://developer.android.com/training/sign-in/biometric-auth Quote Declare the types of authentication that your app supports To define the types of authentication that your app supports, use the BiometricManager.Authenticators interface. The system lets you declare the following types of authentication: BIOMETRIC_STRONG Authentication using a Class 3 biometric, as defined on the Android compatibility definition page. BIOMETRIC_WEAK Authentication using a Class 2 biometric, as defined on the Android compatibility definition page. DEVICE_CREDENTIAL Authentication using a screen lock credential – the user's PIN, pattern, or password. To begin using an authenticator, the user needs to create a PIN, pattern, or password. If the user doesn't already have one, the biometric enrollment flow prompts them to create one. To define the types of biometric authentication that your app accepts, pass an authentication type or a bitwise combination of types into the setAllowedAuthenticators() method. The following code snippet shows how to support authentication using either a Class 3 biometric or a screen lock credential. Edited May 23, 2023 by programmerdelphi2k Share this post Link to post
stacker_liew 5 Posted May 23, 2023 Project->Options->User Permission->Use biometric, Use fingerprint {must tick} Share this post Link to post
programmerdelphi2k 237 Posted May 23, 2023 Just now, stacker_liew said: Project->Options->User Permission->Use biometric, Use fingerprint {must tick} DAMMMMMHHHH 🤪 1 Share this post Link to post
stacker_liew 5 Posted May 23, 2023 Use fingerprint {is deprecated, so untick will be ok} Share this post Link to post
programmerdelphi2k 237 Posted May 23, 2023 it was that I said: deprecated! Share this post Link to post