Exemplo n.º 1
0
        public void Authenticate(IBioAuthCompleted bioAuthCompleted)
        {
            var context          = CrossCurrentActivity.Current.AppContext;
            var biometricManager = BiometricManager.From(context);

            switch (biometricManager.CanAuthenticate())
            {
            case BiometricManager.BiometricSuccess:
                //Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
                ShowBiometicPrompt(bioAuthCompleted);
                break;

            case BiometricManager.BiometricErrorNoHardware:
                bioAuthCompleted.OnCompleted(BioAuthStatus.ENROLL_BiometricErrorNoHardware);
                break;

            case BiometricManager.BiometricErrorHwUnavailable:
                bioAuthCompleted.OnCompleted(BioAuthStatus.ENROLL_BiometricErrorHwUnavailable);
                break;

            case BiometricManager.BiometricErrorNoneEnrolled:
                bioAuthCompleted.OnCompleted(BioAuthStatus.ENROLL_BiometricErrorNoneEnrolled);
                break;
            }

            //MessagingCenter.Send(this, "BioAuth", "Message from Android");
            //bioAuthCompleted.OnCompleted(BioAuthStatus.SUCCESS);
        }
Exemplo n.º 2
0
        private void ShowBiometicPrompt(IBioAuthCompleted bioAuthCompleted)
        {
            var activity = (FragmentActivity)CrossCurrentActivity.Current.Activity;
            var executor = ContextCompat.GetMainExecutor(activity);

            var callback = new BiometricAuthenticationCallback
            {
                Success = (AndroidX.Biometric.BiometricPrompt.AuthenticationResult result) => {
                    try
                    {
                        bioAuthCompleted.OnCompleted(BioAuthStatus.SUCCESS);
                    }
                    catch (SignatureException)
                    {
                        throw new RuntimeException();
                    }
                },
                Failed = () => {
                    // TODO: Show error.
                    bioAuthCompleted.OnCompleted(BioAuthStatus.FAILED);
                },
                Help = (BiometricAcquiredStatus helpCode, ICharSequence helpString) => {
                    // TODO: What do we do here?
                }
            };

            //Create prompt info
            var promptInfo = new AndroidX.Biometric.BiometricPrompt.PromptInfo.Builder()
                             .SetTitle("Biometric login for my app")
                             .SetSubtitle("Log in using your biometric credential")
                             .SetNegativeButtonText("Use account password")
                             .Build();

            //Create prompt
            var biometricPrompt = new AndroidX.Biometric.BiometricPrompt(activity, executor, callback);

            //call Authenticate
            biometricPrompt.Authenticate(promptInfo);
        }