Using biometric authentication has minimal impact on frame rate and memory because it relies on the device's secure hardware and system services. The biometric prompt is handled by the OS, so your app's UI remains smooth, targeting 60fps or higher. Battery usage is low since biometric checks are quick and hardware-accelerated.
Biometric authentication in Android Kotlin - Build, Publish & Deploy
To keep your app responsive during biometric authentication, avoid heavy processing on the main thread. Use asynchronous callbacks for authentication results. Cache authentication state securely to reduce repeated prompts. Also, handle fallback methods gracefully to avoid blocking UI.
Integrating biometric authentication uses Android's built-in BiometricPrompt API, so it adds no extra library size to your app bundle. This keeps your APK or AAB size small and does not affect startup time. Avoid adding third-party biometric libraries to keep the app lightweight.
On Android, biometric authentication uses the BiometricPrompt API, supporting fingerprint, face, and iris depending on device. On iOS, Face ID and Touch ID are accessed via the LocalAuthentication framework. Both platforms handle UI prompts natively, but Android requires checking hardware availability and permissions explicitly. iOS handles permissions automatically.
- Privacy: Clearly explain why biometric data is used in your app's privacy policy.
- Security: Do not store biometric data yourself; use system APIs only.
- User Consent: Ensure users opt-in before biometric authentication.
- Fallback: Provide alternative login methods if biometrics fail or are unavailable.
- Google Play: Follow Google Play's User Data policy regarding biometric usage.
- Apple App Store: If using Face ID/Touch ID on iOS, comply with Apple's Human Interface Guidelines.
Your app takes 5 seconds to load the biometric authentication screen. What's likely wrong?
- You might be performing heavy work on the main thread before showing the biometric prompt.
- Biometric hardware availability checks or permission requests are blocking UI.
- Using a third-party biometric library that adds startup overhead.
Practice
BiometricPrompt in an Android app?Solution
Step 1: Understand the role of BiometricPrompt
BiometricPromptis a system API that shows a standard biometric authentication dialog to the user.Step 2: Identify its main use
It is used specifically for biometric authentication like fingerprint or face recognition, not for login screens or camera access.Final Answer:
To show the system biometric authentication dialog to the user -> Option CQuick Check:
BiometricPrompt = system biometric dialog [OK]
- Confusing biometric prompt with custom login UI
- Thinking it manages network or camera
- Assuming it handles password input
BiometricPrompt instance in Kotlin?Solution
Step 1: Recall BiometricPrompt constructor usage
In Kotlin,BiometricPromptis created by calling its constructor with context, executor, and callback.Step 2: Check each option
Only val biometricPrompt = BiometricPrompt(this, executor, callback) uses the correct constructor syntax. Options A, C, and D use non-existent methods.Final Answer:
val biometricPrompt = BiometricPrompt(this, executor, callback) -> Option BQuick Check:
Constructor call = val biometricPrompt = BiometricPrompt(this, executor, callback) [OK]
- Using non-existent factory methods
- Trying to use Builder pattern which BiometricPrompt doesn't have
- Confusing with other Android APIs
val callback = object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {
println("Success")
}
override fun onAuthenticationFailed() {
println("Failed")
}
}
// Assume biometricPrompt is initialized and authenticate() is called with this callbackSolution
Step 1: Understand callback methods
TheonAuthenticationSucceededmethod runs when biometric authentication is successful.Step 2: Identify printed output on success
InsideonAuthenticationSucceeded, it prints "Success". So on success, "Success" is printed.Final Answer:
Success -> Option DQuick Check:
Success callback prints "Success" [OK]
- Confusing onAuthenticationFailed with success
- Assuming error prints on success
- Thinking no output occurs
val biometricPrompt = BiometricPrompt(this, executor, callback) biometricPrompt.authenticate(promptInfo) // callback object missing override for onAuthenticationError
Solution
Step 1: Check callback completeness
OverridingonAuthenticationErroris recommended but not mandatory; missing it won't crash or prevent compilation.Step 2: Understand effect of missing error override
WithoutonAuthenticationError, errors won't be handled gracefully, but authentication still runs.Final Answer:
It will work but won't handle errors properly -> Option AQuick Check:
Missing error override = no error handling [OK]
- Assuming missing override causes crash
- Thinking code won't compile
- Believing authentication runs without callback
val biometricManager = BiometricManager.from(this)
val canAuthenticate = biometricManager.canAuthenticate(BiometricManager.Authenticators.BIOMETRIC_STRONG or BiometricManager.Authenticators.DEVICE_CREDENTIAL)
if (/* condition here */) {
biometricPrompt.authenticate(promptInfo)
}Solution
Step 1: Understand canAuthenticate return values
canAuthenticatereturnsBIOMETRIC_SUCCESSif biometrics are available and enrolled.Step 2: Choose correct condition to proceed
Only whencanAuthenticate == BIOMETRIC_SUCCESSshould the app show the biometric prompt.Final Answer:
canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS -> Option AQuick Check:
Check for BIOMETRIC_SUCCESS before authenticating [OK]
- Checking for error codes instead of success
- Ignoring enrollment status
- Using wrong constants for condition
Ready to prove it?
Pass the test and this pattern moves unknown
