您可以使用生物识别管理器和生物识别提示进行面部识别吗?

时间:2020-04-23 12:24:35

标签: java android-studio biometrics android-biometric-prompt android-biometric

我当前正在使用生物特征管理器和生物特征提示在google pixel 2上创建指纹认证应用。以下代码适用于该应用。但是,我想知道是否要改为使用Google Pixel 4进行开发,我是否仍可以使用生物识别管理器/生物识别提示来进行面部识别以进行身份​​验证,而不是使用指纹?设备注册的脸部可能是唯一要登录的脸部的前提相同。任何帮助或解释将非常感谢!

import React, { useState } from "react";
import style from "./css/Register.module.css";
import { Table, Button, Icon, TextInput } from "react-materialize";

const ManipulateRegister = () => {
  const [RegisterData, setRegisterData] = useState([
    {
      id: 0,
      name: "W Register",
      value: 0,
      isEdit: false,
    },
    {
      id: 1,
      name: "Z Register",
      value: 0,
      isEdit: false,
    },
    {
      id: 2,
      name: "B Register",
      value: 0,
      isEdit: false,
    },
    {
      id: 3,
      name: "C Register",
      value: 0,
      isEdit: false,
    },
  ]);

  const handleRegisterEditBtn = (register) => {
    var datas = RegisterData;
    datas.forEach((data) => {
      if (data.id === register.id) {
        data.isEdit = true;
      }
    });
    console.log(datas);
    setRegisterData(datas);
  };

  return (
    <div className={style.addressWrapper}>
      <div className={style.addressTableWrapper}>
        <Table centered hoverable responsive striped>
          <thead className="orange lighten-2">
            <tr>
              <th data-field="Namee">Register Name</th>
              <th data-field="value">Value</th>
              <th data-field="action">Action</th>
            </tr>
          </thead>
          <tbody>
            {RegisterData.map((register) => (
              <tr>
                {register.isEdit ? (
                  <div>
                    <TextInput type="number" placeholder="Enter Value" />
                    <Button small waves style={{ margin: "20px" }}>
                      Submit
                    </Button>
                    <Button small waves className="red lighten-2">
                      Cancel
                    </Button>
                  </div>
                ) : (
                  <React.Fragment>
                    <td>{register.name}</td>
                    <td>{register.value}</td>
                    <td>
                      <Button
                        floating
                        icon={<Icon>edit</Icon>}
                        onClick={() => handleRegisterEditBtn(register)}
                      />
                    </td>
                  </React.Fragment>
                )}
              </tr>
            ))}
          </tbody>
        </Table>
      </div>
      <Button node="button" className="red lighten-1" waves="light">
        Reset
      </Button>
    </div>
  );
};
export default ManipulateRegister;


解决方案:

使用使用面部验证进行解锁的设备,使用为面部识别而更改的相同代码。我使用了Google Pixel4。请记住要添加使用生物识别技术的权限。

      // 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);
                        }
                    });

                }

0 个答案:

没有答案