I am using local_auth for biometric authorization.
In case that the device does have biometric support but the user has not enrolled any biometrics (i.e. auth.getAvailableBiometrics()
is empty) is there a way to launch the phone's screen that prompts the user to enrol their biometric data?
I'm sorry if this is a stupid question, I've never done this type of authorization myself, so I don't know how it works.
You can use the local_auth
package for implementing this
To check whether there is local authentication available on this device or not, call canCheckBiometrics
(if you need biometrics support) and/or isDeviceSupported()
(if you just need some device-level authentication):
import 'package:local_auth/local_auth.dart';
final LocalAuthentication auth = LocalAuthentication();
final bool canAuthenticateWithBiometrics = await
auth.canCheckBiometrics;
final bool canAuthenticate = canAuthenticateWithBiometrics || await auth.isDeviceSupported();
Reference doc: Flutter - local_auth
UPDATE
You can launch the security settings
(where fingerprint option is available) using the below code:
startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));
with API >= P
there is Settings.ACTION_FINGERPRINT_ENROLL
& BiometricPrompt
.
@RequiresApi(api = Build.VERSION_CODES.P)
private void startFingerprintEnrollment(@NonNull AppCompatActivity activity) {
Intent intent = new Intent(Settings.ACTION_FINGERPRINT_ENROLL);
activity.startActivityForResult(intent, REQUESTCODE_FINGERPRINT_ENROLLMENT);
}
For API >= M
:
@SuppressWarnings("deprecation")
@RequiresApi(api = Build.VERSION_CODES.M)
private void gotoSecuritySettings(@NonNull AppCompatActivity activity) {
Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
activity.startActivityForResult(intent, REQUESTCODE_SECURITY_SETTINGS);
}