Kevin Walter
Kevin Walter

Reputation: 7166

Flutter - Local_auth (Required security features not enabled)

I'm trying to get biometrics authentication to work again after updating the app I'm developing. But I'm constantly getting the same error when activating it:

 PlatformException(NotAvailable, Required security features not enabled, null, null)

The current one in the store has no problems at all.

I'm using local_auth: 1.1.4
MainActivity.java has been converted to a FragmentedActivity
I'm doing a simple check to see if the biometrics are available. Which they are

bool canCheckBiometrics = await auth.canCheckBiometrics;
List<BiometricType> availableBiometrics =
await auth.getAvailableBiometrics();

print(canCheckBiometrics); //Returns true
print(availableBiometrics.toString()); //Returns [BiometricType.fingerprint]

After that I try to do the authentication

try {
    authenticated = await auth.authenticate(
        biometricOnly: true,
        localizedReason: 'Login with biometrics',
        useErrorDialogs: true,
        stickyAuth: false);
} on PlatformException catch (e) {
    print(e);
}

This returns:

PlatformException(NotAvailable, Required security features not enabled, null, null)

And this is what the plugin comments in the code say.

// Indicates the device does not have a Touch ID/fingerprint scanner.  
const String notAvailable = 'NotAvailable';

I'm not really sure what to check anymore. Is this something new I need to be aware of?

Really hope someone can help me with this issue!

Hope to hear!

Upvotes: 11

Views: 11508

Answers (5)

okan
okan

Reputation: 934

First of all, you need to add a biometric authentication method to your device from settings.

For example if you are using Pixel 2 API 32 as Android Emulator,

  • Go to Settings inside android emulator.
  • Go into Security
  • Under the Device Security section, select Pixel Imprint
  • Android will ask you to put your finger on the sensor, in this part you should click the Touch Sensor button from the Extended Emulator Settings of Android Studio.

Extended Emulator Settings Pixel 2 API 32

  • After turning on fingerprint verification in this way, when you return to the application and try again, you will see that the error is gone.

Similarly, if you are trying with a real device or another emulator, you need to enable fingerprint authentication and try again.

Upvotes: 8

KgaboL
KgaboL

Reputation: 120

I had the same issue and after debugging I discovered that keyguardManager was always null and causing the plugin to throw not enable exception. I had to change the below method in LocalAuthPlugin as follows:

private boolean isDeviceSupported() 
{
   if (keyguardManager == null) return false;
    return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && 
   keyguardManager.isDeviceSecure());
}

to

private boolean isDeviceSupported() 
{
   return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M);
}

It worked for me, hopefully will work for you and others.

Upvotes: 0

Anas Nadeem
Anas Nadeem

Reputation: 887

Go to settings -> security -> fingerprint and add fingerprint lock.

If you are using Android studio emulator then keep in mind that Android Studio emulator provides fake fingerprint scanning.enter image description here

Upvotes: 2

isacjunior
isacjunior

Reputation: 492

I recommend that you verify all capabilities before of try authenticate the user.

Future<bool> authenticateIsAvailable() async {
  final isAvailable = await localAuth.canCheckBiometrics;
  final isDeviceSupported = await localAuth.isDeviceSupported(); 
  return isAvailable && isDeviceSupported;
}

This way, you can call localAuth.authenticate only for phones that have credentials enrolled and probably don't have exceptions. Even though, catch the error if possible.

Upvotes: 7

Julian Perez
Julian Perez

Reputation: 11

I think you don't have a fingerprint activated yet, or you don't have permissions to use it, check the permissions and try again.

Check this out:

https://support.dashlane.com/hc/en-us/articles/203682911-How-to-set-biometric-authentication-or-a-PIN-code-to-unlock-Dashlane-on-Android

Upvotes: 1

Related Questions