smstuebe / xamarin-fingerprint

Xamarin and MvvMCross plugin for authenticate a user via fingerprint sensor
Microsoft Public License
494 stars 118 forks source link

CrossFingerprint.Current.AuthenticateAsync Returns System.NullReferenceException #112

Closed yougotnet closed 2 years ago

yougotnet commented 6 years ago

Using Xamarin I installed the plugin. Added the two lines to the Android Manifest file Added the CrossFingerprint.SetCurrentActivityResolver()

It works fine in iOS but not Android

Here is the code to initiate fingerprint:

async void ConfigureFingerID() { var result = await CrossFingerprint.Current.IsAvailableAsync(true); if (result) { **var fingerprintAuthenticationResult = await CrossFingerprint.Current.AuthenticateAsync("myGopher Authentication");** if (fingerprintAuthenticationResult.Authenticated) { //await DisplayAlert("Finger ID", "Yes", "OK"); CrossSettings.Current.AddOrUpdateValue("FingerID", true); await DisplayAlert("Touch/Face ID Successful", "Touch/Face ID is now setup with the currently logged in writing number and password. If your password changes, you will have to setup Touch/Face ID again.", "OK"); } else { await DisplayAlert("Authentication Failed", "Touch/Face ID authentication failed", "OK"); } } else { await DisplayAlert("Touch/Face ID", "Touch/Face ID not available, make sure Touch/Face ID is setup on the device correctly.", "OK"); } }

smsissuechecker commented 6 years ago

Hi @yougotnet,

I'm the friendly issue checker. It seems like (100.00 %) you haven't used our issue template :cry: I think it is very frustrating for the repository owners, if you ignore them.

If you think it's fine to make an exception, just ignore this message. But if you think it was a mistake to delete the template, please close the issue and create a new one.

Thanks!

jayminnayak commented 6 years ago

Hi @yougotnet

I have fixed this issue in my application by changing Line this

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

to this

CrossFingerprint.SetCurrentActivityResolver(() => this);

yougotnet commented 6 years ago

Thanks! I finally got it working also.

yougotnet commented 6 years ago

I had to add these two line to the MainActivity.cs file for Android:

CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity); Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, savedInstanceState);

jjwils commented 5 years ago

@yougotnet solution fixed it for me

RakeshRaviGovindhan commented 4 years ago

Thanks @jayminnayak, It is working...

Fix of NullReferenceException

//Some times this may get exception //CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);

//you can use this code if you are getting the exception. CrossFingerprint.SetCurrentActivityResolver(() => this);