0

I am currently using the biometric manager and biometric prompt to create a fingerprint authentication app on a google pixel 2. The code below is for that app. However, i was wondering if i changed to developing on a google pixel 4 instead could i still use the biometric manager / biometric prompt to do facial recognition for authentication instead of a fingerprint? The same premise in which the registered face to the device could be the only face to login. Any help or explanation would be great thanks!

      // Building the fingerprint scanner
    final Executor executor = Executors.newSingleThreadExecutor();

    final BiometricPrompt biometricPrompt = new BiometricPrompt.Builder(this)
            .setTitle("Biosecure")
            .setSubtitle("Fingerprint Authentication")
            .setDescription("Please scan your fingerprint")
            .setNegativeButton("cancel", executor, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            }).build();

    // Scanning fingerprint
    btnScanFinger.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v) {
            biometricPrompt.authenticate(new CancellationSignal(), executor, new BiometricPrompt.AuthenticationCallback() {
                @Override
                public void onAuthenticationError(int errorCode, CharSequence errString) {
                    super.onAuthenticationError(errorCode, errString);
                }

                @Override
                public void onAuthenticationHelp(int helpCode, final CharSequence helpString) {
                    super.onAuthenticationHelp(helpCode, helpString);

                }

                @Override
                public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
                    super.onAuthenticationSucceeded(result);

                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run()
                        {

                            Toast.makeText(Login_Biometrics.this, "Fingerprint authenticated successfully", Toast.LENGTH_LONG).show();
                            fingerprintAuth = true;
                            please.setText("Please input your pin");
                            fingerprint.setVisibility(View.INVISIBLE);
                            btnScanFinger.setVisibility(View.INVISIBLE);
                            PinInput.setVisibility(View.VISIBLE);
                        }
                    });

                }

Solution:

Use the same code altered for facial recognition with a device that uses face authentication to unlock . I used a Google Pixel 4. Remember to add permissions for using biometrics.

    <uses-permission android:name="android.permission.USE_BIOMETRIC" />

        // Building the fingerprint scanner
    final Executor executor = Executors.newSingleThreadExecutor();

    final BiometricPrompt biometricPrompt = new BiometricPrompt.Builder(this)
            .setTitle("Biosecure")
            .setSubtitle("Face Authentication")
            .setDescription("Please scan your face")
            .setNegativeButton("cancel", executor, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            }).build();

    btnScanFinger.setOnClickListener(new View.OnClickListener()
    {
        @Override
        public void onClick(View v) {
            biometricPrompt.authenticate(new CancellationSignal(), executor, new BiometricPrompt.AuthenticationCallback() {
                @Override
                public void onAuthenticationError(int errorCode, CharSequence errString) {
                    super.onAuthenticationError(errorCode, errString);
                }

                @Override
                public void onAuthenticationHelp(int helpCode, final CharSequence helpString) {
                    super.onAuthenticationHelp(helpCode, helpString);

                }

                @Override
                public void onAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result) {
                    super.onAuthenticationSucceeded(result);

                    activity.runOnUiThread(new Runnable() {
                        @Override
                        public void run()
                        {

                            Toast.makeText(MainActivity.this, "Face scanned succesfully", Toast.LENGTH_LONG).show();
                            fingerprintAuth = true;

                        }
                    });

                }
Jack1999
  • 71
  • 5
  • `BiometricPrompt` will use whatever form of biometrics that is supported by the device and that the user has enabled, unless they are deemed too insecure (e.g. the facial recognition on some Samsung devices). – Michael Apr 23 '20 at 12:30
  • Thats great to know. Any idea as to how i would edit my fingerprint code to work for facial recognition? Would it require no editing just changes to manifest permissions? Thanks for the help! – Jack1999 Apr 23 '20 at 14:07
  • You shouldn't have to do anything, other than changing those hardcoded "fingerprint" texts you're using. Apps (unfortunately) have no control over which form of biometrics that will be used (aside from the broader WEAK and STRONG categories that were introduced in Android R). It depend on what the device supports and what the user has enabled. – Michael Apr 23 '20 at 14:22

0 Answers0