-->

How to find if user has enrolled any fingerprints

2019-07-31 23:32发布

问题:

I need to identify if the user has any fingerprint register on their device. However, I got an error using this line

  FingerprintManagerCompat  fpm = (FingerprintManagerCompat)CrossCurrentActivity.Current.Activity.GetSystemService(Context.FingerprintService);

``` error ``

{System.InvalidCastException: Specified cast is not valid.
  at app.Droid.lyA.FingerPrint.HasEnrolledFingerprints () [0x00002] in /../../../appmobile/../Droid/lyA/FingerPrint.cs:19 }

This is what I need to return.

回答1:

The correct way of using FingerprintManagerCompat is actually something like this:

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

Good luck!

Revert in case of queries.



回答2:

Converting my comment to an answer-

It seems that there is an error with the casting you did at

FingerprintManagerCompat fpm = (FingerprintManagerCompat)CrossCurrentActivity.Current.Activity.GetSystemService(Context.FingerprintService);

It seems that whatever is being returned here cannot be cast to FingerprintManagerCompat.

As mentioned in another answer, the correct way to use FingerprintManagerCompat is actually -

FingerprintManagerCompat fpm= FingerprintManagerCompat.From(this);

I would suggest changing to this and checking if it solves the issue.