Biometrics - FingerprintManager Xamarin forms on A

2019-07-29 12:37发布

FingerprintManager#isHardwareDetected() and FingerprintManager#hasEnrolledFingerprints(). Both of which are deprecated in Android 28. What else could I use in order to see if fingerprints are enrolled in this version? I saw this as an option.

KeyguardManager keyguardManager =
                    (KeyguardManager) getSystemService(KEYGUARD_SERVICE);

if that option is ok, how to translate it into xamarin forms for example ()

FingerprintManagerCompat fpm= FingerprintManagerCompat.From(CrossCurrentActivity.Current.Activity);

To this :

1条回答
我欲成王,谁敢阻挡
2楼-- · 2019-07-29 12:47

You can use Plugin.Fingerprint to acheved it in android 9.0. https://www.nuget.org/packages/Plugin.Fingerprint/

There is my GIF of demo(If you first run this project, please make sure you have created fingerprint in you device). enter image description here

Because forms just have one activity, If pushed the auth page, we should achieved ActivityLifecycleCallbacks and FingerprintDialogFragment

Here is code of MainApplication , it need the Plugin.CurrentActivity plugin

    [Application]
public class MainApplication : Application, Application.IActivityLifecycleCallbacks
{
    public MainApplication(IntPtr handle, JniHandleOwnership transer)
      : base(handle, transer)
    {
    }

    public override void OnCreate()
    {
        base.OnCreate();
        RegisterActivityLifecycleCallbacks(this);

        CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);

        // uncomment this line to use custom dialog
        //CrossFingerprint.SetDialogFragmentType<MyCustomDialogFragment>();
    }

    public override void OnTerminate()
    {
        base.OnTerminate();
        UnregisterActivityLifecycleCallbacks(this);
    }

    public void OnActivityCreated(Activity activity, Bundle savedInstanceState)
    {
        CrossCurrentActivity.Current.Activity = activity;
    }

    public void OnActivityDestroyed(Activity activity)
    {
    }

    public void OnActivityPaused(Activity activity)
    {
    }

    public void OnActivityResumed(Activity activity)
    {
        CrossCurrentActivity.Current.Activity = activity;
    }

    public void OnActivitySaveInstanceState(Activity activity, Bundle outState)
    {
    }

    public void OnActivityStarted(Activity activity)
    {
        CrossCurrentActivity.Current.Activity = activity;
    }

    public void OnActivityStopped(Activity activity)
    {
    }
}

Here is code of MyCustomDialogFragment

   public class MyCustomDialogFragment : FingerprintDialogFragment
{
    public override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Create your fragment here
    }

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        var view = base.OnCreateView(inflater, container, savedInstanceState);
        view.Background = new ColorDrawable(Color.Blue);
        return view;
    }
}

There is my code of my demo.

https://github.com/851265601/FrigerPrintDemo

查看更多
登录 后发表回答