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
class MainActivity : AppCompatActivity() { | |
... | |
private lateinit var biometricPrompt: BiometricPrompt | |
private lateinit var promptInfo: BiometricPrompt.PromptInfo | |
... | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
... |
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
class MainActivity : AppCompatActivity() { | |
private lateinit var biometricPrompt: BiometricPrompt | |
private lateinit var promptInfo: BiometricPrompt.PromptInfo | |
private var readyToEncrypt: Boolean = false | |
... | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
... |
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
class MainActivity : AppCompatActivity() { | |
private lateinit var textInputView: AppCompatEditText | |
private lateinit var textOutputView: AppCompatTextView | |
private lateinit var biometricPrompt: BiometricPrompt | |
private lateinit var promptInfo: BiometricPrompt.PromptInfo | |
private var readyToEncrypt: Boolean = false | |
private lateinit var cryptographyManager: CryptographyManager | |
private lateinit var secretKeyName: String | |
private lateinit var ciphertext:ByteArray |
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 onAuthenticationError(errorCode: Int, errString: CharSequence) { | |
super.onAuthenticationError(errorCode, errString) | |
Log.d(TAG, "$errorCode :: $errString") | |
if (errorCode == BiometricPrompt.ERROR_USER_CANCELED) { | |
handleUserCancelation() // this is your custom function | |
} | |
} | |
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
if (ciphertextWrapper != null) { | |
// user has already enabled biometrics | |
} else { | |
// biometrics has not been enabled | |
} |
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
binding.useBiometrics.setOnClickListener { | |
showBiometricPromptForEncryption() | |
} | |
.... | |
private fun showBiometricPromptForEncryption() { | |
val canAuthenticate = BiometricManager.from(applicationContext).canAuthenticate() | |
if (canAuthenticate == BiometricManager.BIOMETRIC_SUCCESS) { | |
val secretKeyName = SECRET_KEY_NAME | |
cryptographyManager = CryptographyManager() |
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
dependencies { | |
implementation 'com.google.android.gms:play-services-nearby:18.0.0' | |
} |
OlderNewer