This file contains 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' | |
} |
This file contains 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 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 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 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 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 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 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 | |
... | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
... | |
biometricPrompt = createBiometricPrompt() |
This file contains 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
def biometric_version = '1.0.1' | |
implementation "androidx.biometric:biometric:$biometric_version" |
This file contains 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
interface CryptographyManager { | |
/** | |
* This method first gets or generates an instance of SecretKey and then initializes the Cipher | |
* with the key. The secret key uses [ENCRYPT_MODE][Cipher.ENCRYPT_MODE] is used. | |
*/ | |
fun getInitializedCipherForEncryption(keyName: String): Cipher | |
/** | |
* This method first gets or generates an instance of SecretKey and then initializes the Cipher |
NewerOlder