Xamarin为Android开发生物识别人脸识别

des4xlb0  于 2023-04-18  发布在  Android
关注(0)|答案(1)|浏览(208)

我想在我的应用程序中包括一个生物识别登录系统,允许用户使用他们的脸登录,类似于你如何可以用FaceID在iPhone上登录.我使用插件.指纹NuGet包来实现这一点.虽然我能够让它在Android上与指纹工作,我似乎不能让它在Android上使用人脸识别,而在iOS上它会带来一个FaceID提示
是我缺少了一个权限,还是在android上无法实现?
代码如下:

public async void BiometricClicked()
    {
        if (!bioOn)
        {
            var request = new AuthenticationRequestConfiguration("Biometric Setup.", "Setup Biometric Login");
            var result = await CrossFingerprint.Current.AuthenticateAsync(request);

            if (result.Authenticated)
            {
                bioOn = true;
                Preferences.Set("BioLogin", DealerName);
                Preferences.Set("BioPass", dealerPass);
                Preferences.Set("BioOn", bioOn);
                UserDialogs.Instance.Alert("Biometric Login successfully activated.", "Biometric", "Ok");

            }
            else
            {
                UserDialogs.Instance.Alert("Cannot setup biometric.", "Biometric", "Ok");
                
            }
        }
        else
        {
            var prompt = await UserDialogs.Instance.ConfirmAsync("Do you wish to turn off biometric login?", "Biometric", "Yes", "No");
            if (prompt)
            {
                Preferences.Remove("BioLogin");
                Preferences.Remove("BioPass");
                bioOn = false;
                Preferences.Set("BioOn", bioOn);
                UserDialogs.Instance.Alert("Biometric login deactivated.", "Biometric", "Ok");
            }
        }

    }

Android.manifest中的权限:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.USE_BIOMETRIC" />

MainActivity.cs:

protected override void OnCreate(Bundle savedInstanceState)
    {
        
        
        base.OnCreate(savedInstanceState);
        
        
        CrossFingerprint.SetCurrentActivityResolver(() => Xamarin.Essentials.Platform.CurrentActivity);
       
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
      
        LoadApplication(new App());

    }
vfwfrxfs

vfwfrxfs1#

我能够在三星Galaxy Note8上启用面部解锁,方法是同时注册指纹和面部识别,然后将首选生物识别设置为面部识别

相关问题