Biyometrik kimlik doğrulama iletişim kutusu göster

Uygulamanızdaki hassas bilgileri veya premium içeriği korumanın yöntemlerinden biri, yüz tanıma veya parmak izi tanıma gibi özellikleri kullanarak biyometrik kimlik doğrulama istemektir. Bu kılavuzda, uygulamanızda biyometrik giriş akışlarını nasıl destekleyeceğiniz açıklanmaktadır.

Genel bir kural olarak, şu cihazlarda ilk oturum açma işlemi için Kimlik Bilgisi Yöneticisi cihaz. Sonraki yeniden yetkilendirmeler, Biyometrik İstem veya Kimlik Bilgisi Yöneticisi ile yapılabilir. Biyometrik İstem'in avantajı, daha fazla özelleştirme seçeneği sunmasıdır. Kimlik Bilgisi Yöneticisi ise her iki akışta da tek bir uygulama sunar.

Uygulamanızın desteklediği kimlik doğrulama türlerini beyan etme

Uygulamanızın desteklediği kimlik doğrulama türlerini tanımlamak için BiometricManager.Authenticators kullanır. Sistem, aşağıdaki kimlik doğrulama türlerini belirtmenize olanak tanır:

BIOMETRIC_STRONG
Aşağıdaki gibi 3. Sınıf biyometri kullanarak kimlik doğrulama Android uyumluluğu tanım sayfasını ziyaret edin.
BIOMETRIC_WEAK
Android uyumluluğu tanımı sayfasında tanımlandığı şekilde 2. sınıf biyometrik kullanarak kimlik doğrulama.
DEVICE_CREDENTIAL
Ekran kilidi kimlik bilgisini (kullanıcının PIN'i, deseni veya numarası) kullanarak kimlik doğrulama şifre.

Kimlik doğrulayıcıyı kullanmaya başlamak için kullanıcının bir PIN oluşturması gerekir. veya şifre girin. Kullanıcının zaten biyometrisi yoksa oluşturmaları istenir.

Uygulamanızın kabul ettiği biyometrik kimlik doğrulama türlerini tanımlamak için veya türlerin bit tabanlı birleşimini setAllowedAuthenticators() yöntemidir. Aşağıdaki kod snippet'i, 3. Sınıf biyometri veya ekran kilidi kimlik bilgisi bulunmalıdır.

Kotlin

// Lets the user authenticate using either a Class 3 biometric or
// their lock screen credential (PIN, pattern, or password).
promptInfo = BiometricPrompt.PromptInfo.Builder()
        .setTitle("Biometric login for my app")
        .setSubtitle("Log in using your biometric credential")
        .setAllowedAuthenticators(BIOMETRIC_STRONG or DEVICE_CREDENTIAL)
        .build()

Java

// Lets user authenticate using either a Class 3 biometric or
// their lock screen credential (PIN, pattern, or password).
promptInfo = new BiometricPrompt.PromptInfo.Builder()
        .setTitle("Biometric login for my app")
        .setSubtitle("Log in using your biometric credential")
        .setAllowedAuthenticators(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)
        .build();

Aşağıdaki kimlik doğrulayıcı türü kombinasyonları Android 10 (API düzeyi 29) ve önceki sürümler: DEVICE_CREDENTIAL ve BIOMETRIC_STRONG | DEVICE_CREDENTIAL. PIN olup olmadığını kontrol etmek için: veya şifreyi öğrenmek için KeyguardManager.isDeviceSecure() yöntemidir.

Biyometrik kimlik doğrulamanın kullanılabilir olup olmadığını kontrol etme

Uygulamanızın hangi kimlik doğrulama öğelerini desteklediğine karar verdikten sonra kullanılabilir. Bunun için, setAllowedAuthenticators() yöntemini kullanarak tanımladığınız türlerin aynı bit kombinasyonunu canAuthenticate() yöntemine iletin. Gerekirse, ACTION_BIOMETRIC_ENROLL amacı eyleme dökülebilir. Amaç ekstrasında, uygulamanızın kabul eder. Bu intent, kullanıcıdan uygulamanızın kabul ettiği bir kimlik doğrulayıcı için kimlik bilgilerini kaydetmesini ister.

Kotlin

val biometricManager = BiometricManager.from(this)
when (biometricManager.canAuthenticate(BIOMETRIC_STRONG or DEVICE_CREDENTIAL)) {
    BiometricManager.BIOMETRIC_SUCCESS ->
        Log.d("MY_APP_TAG", "App can authenticate using biometrics.")
    BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE ->
        Log.e("MY_APP_TAG", "No biometric features available on this device.")
    BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE ->
        Log.e("MY_APP_TAG", "Biometric features are currently unavailable.")
    BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED -> {
        // Prompts the user to create credentials that your app accepts.
        val enrollIntent = Intent(Settings.ACTION_BIOMETRIC_ENROLL).apply {
            putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED,
                BIOMETRIC_STRONG or DEVICE_CREDENTIAL)
        }
        startActivityForResult(enrollIntent, REQUEST_CODE)
    }
}

Java

BiometricManager biometricManager = BiometricManager.from(this);
switch (biometricManager.canAuthenticate(BIOMETRIC_STRONG | DEVICE_CREDENTIAL)) {
    case BiometricManager.BIOMETRIC_SUCCESS:
        Log.d("MY_APP_TAG", "App can authenticate using biometrics.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
        Log.e("MY_APP_TAG", "No biometric features available on this device.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
        Log.e("MY_APP_TAG", "Biometric features are currently unavailable.");
        break;
    case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
        // Prompts the user to create credentials that your app accepts.
        final Intent enrollIntent = new Intent(Settings.ACTION_BIOMETRIC_ENROLL);
        enrollIntent.putExtra(Settings.EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED,
                BIOMETRIC_STRONG | DEVICE_CREDENTIAL);
        startActivityForResult(enrollIntent, REQUEST_CODE);
        break;
}

Kullanıcının kimlik doğrulamasını nasıl yaptığını belirleme

Kullanıcı kimlik doğrulamasını yaptıktan sonra, şunu çağırarak cihaz kimlik bilgisi veya biyometrik kimlik bilgisi getAuthenticationType().

Giriş istemini görüntüle

Kullanıcıdan biyometrik kimlik bilgilerini kullanarak kimlik doğrulaması yapmasını isteyen bir sistem istemi görüntülemek için Biyometrik kitaplığı'nı kullanın. Sistem tarafından sağlanan bu iletişim kutusu, kullanan uygulamalarda tutarlı olduğundan daha güvenilir bir kullanıcı deneyimi oluşturur. Şekil 1'de örnek bir iletişim kutusu gösterilmektedir.

İletişim kutusunu gösteren ekran görüntüsü.
Şekil 1. Biyometrik isteyen sistem iletişim kutusu doğrulama.

Biyometrik kitaplığını kullanarak uygulamanıza biyometrik kimlik doğrulama eklemek için aşağıdaki adımları tamamlayın:

  1. Uygulama modülünüzün build.gradle dosyasına androidx.biometric kitaplığına bağımlılık ekleyin.

  2. Biyometrik giriş iletişim kutusunu barındıran etkinlikte veya parçada aşağıdaki kod snippet'inde gösterilen mantığı kullanarak iletişim kutusunu açın:

    Kotlin

    private lateinit var executor: Executor
    private lateinit var biometricPrompt: BiometricPrompt
    private lateinit var promptInfo: BiometricPrompt.PromptInfo
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_login)
        executor = ContextCompat.getMainExecutor(this)
        biometricPrompt = BiometricPrompt(this, executor,
                object : BiometricPrompt.AuthenticationCallback() {
            override fun onAuthenticationError(errorCode: Int,
                    errString: CharSequence) {
                super.onAuthenticationError(errorCode, errString)
                Toast.makeText(applicationContext,
                    "Authentication error: $errString", Toast.LENGTH_SHORT)
                    .show()
            }
    
            override fun onAuthenticationSucceeded(
                    result: BiometricPrompt.AuthenticationResult) {
                super.onAuthenticationSucceeded(result)
                Toast.makeText(applicationContext,
                    "Authentication succeeded!", Toast.LENGTH_SHORT)
                    .show()
            }
    
            override fun onAuthenticationFailed() {
                super.onAuthenticationFailed()
                Toast.makeText(applicationContext, "Authentication failed",
                    Toast.LENGTH_SHORT)
                    .show()
            }
        })
    
        promptInfo = BiometricPrompt.PromptInfo.Builder()
                .setTitle("Biometric login for my app")
                .setSubtitle("Log in using your biometric credential")
                .setNegativeButtonText("Use account password")
                .build()
    
        // Prompt appears when user clicks "Log in".
        // Consider integrating with the keystore to unlock cryptographic operations,
        // if needed by your app.
        val biometricLoginButton =
                findViewById<Button>(R.id.biometric_login)
        biometricLoginButton.setOnClickListener {
            biometricPrompt.authenticate(promptInfo)
        }
    }

    Java

    private Executor executor;
    private BiometricPrompt biometricPrompt;
    private BiometricPrompt.PromptInfo promptInfo;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        executor = ContextCompat.getMainExecutor(this);
        biometricPrompt = new BiometricPrompt(MainActivity.this,
                executor, new BiometricPrompt.AuthenticationCallback() {
            @Override
            public void onAuthenticationError(int errorCode,
                    @NonNull CharSequence errString) {
                super.onAuthenticationError(errorCode, errString);
                Toast.makeText(getApplicationContext(),
                    "Authentication error: " + errString, Toast.LENGTH_SHORT)
                    .show();
            }
    
            @Override
            public void onAuthenticationSucceeded(
                    @NonNull BiometricPrompt.AuthenticationResult result) {
                super.onAuthenticationSucceeded(result);
                Toast.makeText(getApplicationContext(),
                    "Authentication succeeded!", Toast.LENGTH_SHORT).show();
            }
    
            @Override
            public void onAuthenticationFailed() {
                super.onAuthenticationFailed();
                Toast.makeText(getApplicationContext(), "Authentication failed",
                    Toast.LENGTH_SHORT)
                    .show();
            }
        });
    
        promptInfo = new BiometricPrompt.PromptInfo.Builder()
                .setTitle("Biometric login for my app")
                .setSubtitle("Log in using your biometric credential")
                .setNegativeButtonText("Use account password")
                .build();
    
        // Prompt appears when user clicks "Log in".
        // Consider integrating with the keystore to unlock cryptographic operations,
        // if needed by your app.
        Button biometricLoginButton = findViewById(R.id.biometric_login);
        biometricLoginButton.setOnClickListener(view -> {
                biometricPrompt.authenticate(promptInfo);
        });
    }

Kimlik doğrulamaya dayalı bir kriptografik çözüm kullanın

Uygulamanızdaki hassas bilgileri daha da korumak için CryptoObject örneği kullanarak biyometrik kimlik doğrulama iş akışınıza kriptografiyi dahil edebilirsiniz. Çerçeve aşağıdaki kriptografik nesneleri destekler: Signature, Cipher ve Mac.

Kullanıcı, biyometrik istem kullanarak başarıyla kimlik doğruladıktan sonra uygulamanız şifreleme işlemi yapılır. Örneğin, bir Cipher nesnesini görürseniz uygulamanız daha sonra bir SecretKey nesnesini ifade eder.

Aşağıdaki bölümlerde, Cipher nesnesi ve Verilerin şifreleneceği SecretKey nesnesi. Her örnekte şunlar kullanılır: yöntemleri:

Kotlin

private fun generateSecretKey(keyGenParameterSpec: KeyGenParameterSpec) {
    val keyGenerator = KeyGenerator.getInstance(
            KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore")
    keyGenerator.init(keyGenParameterSpec)
    keyGenerator.generateKey()
}

private fun getSecretKey(): SecretKey {
    val keyStore = KeyStore.getInstance("AndroidKeyStore")

    // Before the keystore can be accessed, it must be loaded.
    keyStore.load(null)
    return keyStore.getKey(KEY_NAME, null) as SecretKey
}

private fun getCipher(): Cipher {
    return Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/"
            + KeyProperties.BLOCK_MODE_CBC + "/"
            + KeyProperties.ENCRYPTION_PADDING_PKCS7)
}

Java

private void generateSecretKey(KeyGenParameterSpec keyGenParameterSpec) {
    KeyGenerator keyGenerator = KeyGenerator.getInstance(
            KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
    keyGenerator.init(keyGenParameterSpec);
    keyGenerator.generateKey();
}

private SecretKey getSecretKey() {
    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");

    // Before the keystore can be accessed, it must be loaded.
    keyStore.load(null);
    return ((SecretKey)keyStore.getKey(KEY_NAME, null));
}

private Cipher getCipher() {
    return Cipher.getInstance(KeyProperties.KEY_ALGORITHM_AES + "/"
            + KeyProperties.BLOCK_MODE_CBC + "/"
            + KeyProperties.ENCRYPTION_PADDING_PKCS7);
}

Yalnızca biyometrik kimlik bilgileri kullanarak kimlik doğrula

Uygulamanız, kilidi açmak için biyometrik kimlik bilgileri gerektiren bir gizli anahtar kullanıyorsa kullanıcının, uygulamanızdan önce her seferinde biyometrik kimlik bilgilerini doğrulaması gerekir anahtara erişir.

Hassas bilgileri yalnızca kullanıcı biyometrik kimlik bilgilerini kullanarak kimlik doğruladıktan sonra şifrelemek için aşağıdaki adımları tamamlayın:

  1. Aşağıdaki KeyGenParameterSpec yapılandırmasını kullanan bir anahtar oluşturun:

    Kotlin

    generateSecretKey(KeyGenParameterSpec.Builder(
            KEY_NAME,
            KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
            .setUserAuthenticationRequired(true)
            // Invalidate the keys if the user has registered a new biometric
            // credential, such as a new fingerprint. Can call this method only
            // on Android 7.0 (API level 24) or higher. The variable
            // "invalidatedByBiometricEnrollment" is true by default.
            .setInvalidatedByBiometricEnrollment(true)
            .build())

    Java

    generateSecretKey(new KeyGenParameterSpec.Builder(
            KEY_NAME,
            KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
            .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
            .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
            .setUserAuthenticationRequired(true)
            // Invalidate the keys if the user has registered a new biometric
            // credential, such as a new fingerprint. Can call this method only
            // on Android 7.0 (API level 24) or higher. The variable
            // "invalidatedByBiometricEnrollment" is true by default.
            .setInvalidatedByBiometricEnrollment(true)
            .build());
  2. Şifre içeren bir biyometrik kimlik doğrulama iş akışı başlatın:

    Kotlin

    biometricLoginButton.setOnClickListener {
        // Exceptions are unhandled within this snippet.
        val cipher = getCipher()
        val secretKey = getSecretKey()
        cipher.init(Cipher.ENCRYPT_MODE, secretKey)
        biometricPrompt.authenticate(promptInfo,
                BiometricPrompt.CryptoObject(cipher))
    }

    Java

    biometricLoginButton.setOnClickListener(view -> {
        // Exceptions are unhandled within this snippet.
        Cipher cipher = getCipher();
        SecretKey secretKey = getSecretKey();
        cipher.init(Cipher.ENCRYPT_MODE, secretKey);
        biometricPrompt.authenticate(promptInfo,
                new BiometricPrompt.CryptoObject(cipher));
    });
  3. Biyometrik kimlik doğrulama geri çağırma çağrılarınızda, hassas bilgileri şifrelemek için gizli anahtarı kullanın:

    Kotlin

    override fun onAuthenticationSucceeded(
            result: BiometricPrompt.AuthenticationResult) {
        val encryptedInfo: ByteArray = result.cryptoObject.cipher?.doFinal(
            // plaintext-string text is whatever data the developer would like
            // to encrypt. It happens to be plain-text in this example, but it
            // can be anything
                plaintext-string.toByteArray(Charset.defaultCharset())
        )
        Log.d("MY_APP_TAG", "Encrypted information: " +
                Arrays.toString(encryptedInfo))
    }

    Java

    @Override
    public void onAuthenticationSucceeded(
            @NonNull BiometricPrompt.AuthenticationResult result) {
        // NullPointerException is unhandled; use Objects.requireNonNull().
        byte[] encryptedInfo = result.getCryptoObject().getCipher().doFinal(
            // plaintext-string text is whatever data the developer would like
            // to encrypt. It happens to be plain-text in this example, but it
            // can be anything
                plaintext-string.getBytes(Charset.defaultCharset()));
        Log.d("MY_APP_TAG", "Encrypted information: " +
                Arrays.toString(encryptedInfo));
    }

Biyometrik veya kilit ekranı kimlik bilgilerini kullanarak kimlik doğrulama

Biyometri aracılığıyla kimlik doğrulamasına olanak tanıyan gizli bir anahtar kullanabilirsiniz kimlik bilgileri veya kilit ekranı kimlik bilgileri (PIN, desen veya şifre). Zaman bir geçerlilik dönemi belirtin. Bu süre zarfında uygulamanız, kullanıcının kimliğini yeniden doğrulaması gerekmeden birden fazla kriptografik işlem gerçekleştirebilir.

Kullanıcı biyometrik veya kimlik bilgisi kullanarak kimlik doğrulaması yaptıktan sonra hassas bilgileri şifrelemek için kilit ekranı kimlik bilgileri için aşağıdaki adımları tamamlayın:

  1. Aşağıdaki KeyGenParameterSpec yapılandırmasını kullanan bir anahtar oluşturun:

    Kotlin

    generateSecretKey(KeyGenParameterSpec.Builder(
        KEY_NAME,
        KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
        .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
        .setUserAuthenticationRequired(true)
        .setUserAuthenticationParameters(VALIDITY_DURATION_SECONDS,
                ALLOWED_AUTHENTICATORS)
        .build())

    Java

    generateSecretKey(new KeyGenParameterSpec.Builder(
        KEY_NAME,
        KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
        .setBlockModes(KeyProperties.BLOCK_MODE_CBC)
        .setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
        .setUserAuthenticationRequired(true)
        .setUserAuthenticationParameters(VALIDITY_DURATION_SECONDS,
                ALLOWED_AUTHENTICATORS)
        .build());
  2. Kullanıcı kimliğini doğruladıktan sonraki VALIDITY_DURATION_SECONDS saniye içinde hassas bilgileri şifreleyin:

    Kotlin

    private fun encryptSecretInformation() {
        // Exceptions are unhandled for getCipher() and getSecretKey().
        val cipher = getCipher()
        val secretKey = getSecretKey()
        try {
            cipher.init(Cipher.ENCRYPT_MODE, secretKey)
            val encryptedInfo: ByteArray = cipher.doFinal(
                // plaintext-string text is whatever data the developer would
                // like to encrypt. It happens to be plain-text in this example,
                // but it can be anything
                    plaintext-string.toByteArray(Charset.defaultCharset()))
            Log.d("MY_APP_TAG", "Encrypted information: " +
                    Arrays.toString(encryptedInfo))
        } catch (e: InvalidKeyException) {
            Log.e("MY_APP_TAG", "Key is invalid.")
        } catch (e: UserNotAuthenticatedException) {
            Log.d("MY_APP_TAG", "The key's validity timed out.")
            biometricPrompt.authenticate(promptInfo)
        }

    Java

    private void encryptSecretInformation() {
        // Exceptions are unhandled for getCipher() and getSecretKey().
        Cipher cipher = getCipher();
        SecretKey secretKey = getSecretKey();
        try {
            // NullPointerException is unhandled; use Objects.requireNonNull().
            ciper.init(Cipher.ENCRYPT_MODE, secretKey);
            byte[] encryptedInfo = cipher.doFinal(
                // plaintext-string text is whatever data the developer would
                // like to encrypt. It happens to be plain-text in this example,
                // but it can be anything
                    plaintext-string.getBytes(Charset.defaultCharset()));
        } catch (InvalidKeyException e) {
            Log.e("MY_APP_TAG", "Key is invalid.");
        } catch (UserNotAuthenticatedException e) {
            Log.d("MY_APP_TAG", "The key's validity timed out.");
            biometricPrompt.authenticate(promptInfo);
        }
    }

Kullanım başına kimlik doğrulama anahtarları kullanarak kimlik doğrulama

Örnekinizde kullanım başına kimlik doğrulama anahtarları için destek sağlayabilirsiniz. BiometricPrompt. Böyle bir anahtar kullanıcının biyometrik kimlik bilgisi veya cihaz sunmasını gerektirir Kimlik bilgisi içeren bir e-posta alırsınız. o tuşa basın. Kullanım başına kimlik anahtarları, yüksek tutarda ödeme yapmak veya bir kişinin sağlık kayıtlarını güncellemek.

Bir BiometricPrompt nesnesini kullanım başına kimlik doğrulama anahtarıyla ilişkilendirmek için aşağıdakine benzer bir kod ekleyin:

Kotlin

val authPerOpKeyGenParameterSpec =
        KeyGenParameterSpec.Builder("myKeystoreAlias", key-purpose)
    // Accept either a biometric credential or a device credential.
    // To accept only one type of credential, include only that type as the
    // second argument.
    .setUserAuthenticationParameters(0 /* duration */,
            KeyProperties.AUTH_BIOMETRIC_STRONG or
            KeyProperties.AUTH_DEVICE_CREDENTIAL)
    .build()

Java

KeyGenParameterSpec authPerOpKeyGenParameterSpec =
        new KeyGenParameterSpec.Builder("myKeystoreAlias", key-purpose)
    // Accept either a biometric credential or a device credential.
    // To accept only one type of credential, include only that type as the
    // second argument.
    .setUserAuthenticationParameters(0 /* duration */,
            KeyProperties.AUTH_BIOMETRIC_STRONG |
            KeyProperties.AUTH_DEVICE_CREDENTIAL)
    .build();

Kullanıcı tarafından belirli bir işlem yapılmadan kimlik doğrulayın

Varsayılan olarak, sistem kullanıcıların belirli bir işlemi gerçekleştirmesini gerektirir: Biyometrik kimlik bilgileri kabul edildikten sonra bir düğmeye basarak. Bu onay kutusu gösteriliyorsa, yapılandırma tercih edilir. satın alma gibi yüksek riskli işlemlerdir.

Uygulamanızda daha düşük riskli bir işlem için biyometrik kimlik doğrulama iletişim kutusu gösteriliyorsa Ancak sisteme, kullanıcının oturum açması gerekmeyen kimlik doğrulamayı onaylayın. Bu ipucu, kullanıcının uygulamanızdaki içeriği görüntülemesine olanak tanıyabilir gibi pasif bir yöntem kullanarak yeniden kimlik doğrulama işleminden sonra daha hızlı bir şekilde iris tabanlı tanıma Bu ipucunu sağlamak için false öğesini setConfirmationRequired() yöntemini kullanabilirsiniz.

Şekil 2'de aynı iletişim kutusunun iki sürümü gösterilmektedir. Bir sürüm için kullanıcının açık bir işlem yapması gerekirken diğer sürüm için bu işlem gerekmez.

İletişim kutusunun ekran görüntüsü İletişim kutusunun ekran görüntüsü
Şekil 2. Kullanıcı onayı olmadan (üstte) ve kullanıcı onayı ile (altta) yüz kimlik doğrulama.

Aşağıdaki kod snippet'inde, kullanılmayan bir iletişim kutusunun nasıl gösterileceği Kimlik doğrulama sürecinin tamamlanması için kullanıcının açık bir şekilde işlemi yapması gerekir:

Kotlin

// Lets the user authenticate without performing an action, such as pressing a
// button, after their biometric credential is accepted.
promptInfo = BiometricPrompt.PromptInfo.Builder()
        .setTitle("Biometric login for my app")
        .setSubtitle("Log in using your biometric credential")
        .setNegativeButtonText("Use account password")
        .setConfirmationRequired(false)
        .build()

Java

// Lets the user authenticate without performing an action, such as pressing a
// button, after their biometric credential is accepted.
promptInfo = new BiometricPrompt.PromptInfo.Builder()
        .setTitle("Biometric login for my app")
        .setSubtitle("Log in using your biometric credential")
        .setNegativeButtonText("Use account password")
        .setConfirmationRequired(false)
        .build();

Biyometrik olmayan kimlik bilgilerine yedek olarak izin verme

Uygulamanızın biyometrik veya cihaz kullanarak kimlik doğrulamaya izin vermesini istiyorsanız kimlik bilginiz varsa, uygulamanızın cihazları desteklediğini, kimlik bilgileri DEVICE_CREDENTIAL setAllowedAuthenticators().

Uygulamanızda şu anda createConfirmDeviceCredentialIntent() veya setDeviceCredentialAllowed() bu özelliği sağlamak için setAllowedAuthenticators() kullanımına geçin.

Ek kaynaklar

Android'de biyometrik kimlik doğrulama hakkında daha fazla bilgi edinmek için aşağıdaki kaynaklara göz atın.

Blog yayınları