1

以下は、生体認証機能を検出するための私のコードです

class MainActivity : AppCompatActivity() {

    private var executor: Executor? = null
    private var biometricPrompt: BiometricPrompt? = null
    private var promptInfo: BiometricPrompt.PromptInfo? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val bioMetricManager = BiometricManager.from(this)

        when (bioMetricManager.canAuthenticate()) {
            BiometricManager.BIOMETRIC_SUCCESS -> {
                executor = ContextCompat.getMainExecutor(this)

                promptInfo = BiometricPrompt.PromptInfo.Builder().setTitle("Biometric login for leaao")
                    .setSubtitle("Log in using biometric credentials").setDeviceCredentialAllowed(true).build()

                biometricPrompt = BiometricPrompt(this,
                    executor!!, object : BiometricPrompt.AuthenticationCallback() {
                        override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
                            super.onAuthenticationError(errorCode, errString)
                            Log.i("here4","Authentication error: $errString")
                        }

                        override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
                            super.onAuthenticationSucceeded(result)
                            Log.i("here5","Success")
                        }

                        override fun onAuthenticationFailed() {
                            super.onAuthenticationFailed()
                            Log.i("here6","Authentication failed: ")
                        }
                    })

                biometricPrompt?.authenticate(promptInfo!!)
            }
            BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE -> {
                Log.i("here","No biometric features available on this device.")
            }
            BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE -> {
                Log.i("here2","Biometric features are currently unavailable.")
            }
            BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> {
                Log.i("here3","The user hasn't associated any biometric credentials with their account.")
            }
        }
    }
}

<uses-permission android:name="android.permission.USE_BIOMETRIC" />マニフェストファイルに追加し implementation 'androidx.biometric:biometric:1.0.1'、gradleに追加しました

それでも私のコードは生体認証プロンプトを検出できません。モバイルで顔認識を有効にしましたが、アプリを開いたときに機能しません。BIOMETRIC_ERROR_HW_UNAVAILABLE私のコードでは大文字と小文字が区別されます。

4

0 に答える 0