This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CameraView | CameraController | |
|---|---|---|
| - | getInitializationFuture() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| createAndStoreSecretKey() | |
| val cipher = createAndConfigureCipher() | |
| val cryptoObject = CryptoObject(cipher) | |
| biometricPrompt.authenticate(promptinfo, cyptoObject) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { | |
| val cipher = result.cryptoObject?.cipher ?: return | |
| val plainData = "Hello world!" // Whatever data you want to encrypt | |
| val cipherData = cipher.doFinal(plainData.toByteArray(Charsets.UTF_8)) // Encrypted data | |
| // Do something with the encrypted data | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val biometricManager = BiometricManager.from(context) | |
| val authenticationTypes = BIOMETRIC_WEAK or DEVICE_CREDENTIAL | |
| val canAuthenticate = biometricManager.canAuthenticate(authenticationTypes) | |
| if (canAuthenticate == BIOMETRIC_SUCCESS) { | |
| // The device supports weak biometric authentication or non-biometric authentication, e.g. PIN | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Pre-Android R | Android R and above | ||
|---|---|---|---|
| Check if biometric authentication is supported | BiometricsManager.canAuthenticate() | BiometricsManager.canAuthenticate(authenticators) | |
| Define allowed authenticators | PromptInfo.Builder.setDeviceCredentialAllowed(boolean) | PromptInfo.Builder.setAllowedAuthenticators(authenticators) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val biometricPrompt = BiometricPrompt( | |
| activity, // Activity or Fragment | |
| executor, // Optional. Defines the executor on which the callbacks are triggered | |
| authenticationCallback | |
| ) | |
| // Show the authentication prompt | |
| biometricPrompt.authenticate(promptInfo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val builder = PromptInfo.Builder() | |
| .setTitle(/* Title */) | |
| .setSubtitle(/* Subtitle */) | |
| .setDescription(/* Description */) | |
| // Set a negative button. It would typically display "Cancel" | |
| builder.setNegativeButtonText(/* Negative button label. E.g. "Cancel" */) | |
| // Show a confirmation button after authentication succeeds | |
| // Useful for certain operations, e.g. Ones that involve payment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val authenticationCallback = object : BiometricPrompt.AuthenticationCallback() { | |
| override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) { | |
| // Authentication succeeded | |
| } | |
| override fun onAuthenticationError(errorCode: Int, errString: CharSequence) { | |
| // Authentication errored out. Verify error code and message | |
| } | |
| override fun onAuthenticationFailed() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val biometricManager = BiometricManager.from(context) | |
| val canAuthenticate = biometricManager.canAuthenticate() | |
| if (canAuthenticate == BIOMETRIC_SUCCESS) { | |
| // The device supports biometric authentication | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Thermal status code | Description | Example of use | |
|---|---|---|---|
| NONE | No throttling | Enable features | |
| LIGHT | Light throttling where the UX isn't impacted | Disable features the user may not notice | |
| MODERATE | Moderate throttling where the UX is not largely impacted | Disable add-on features | |
| SEVERE | Severe throttling where the UX is largely impacted | Warn the user of the thermal issues | |
| CRITICAL | Platform has done everything to reduce power | Disable non-essential features to keep only basic functionality | |
| EMERGENCY | Key components in platform are shutting down. Device functionalities will be limited | Prepare for shutdown | |
| SHUTDOWN | Must shutdown immediately | - |