Skip to content

Instantly share code, notes, and snippets.

@isaidamier
Created February 19, 2020 18:01
Show Gist options
  • Save isaidamier/624155fdf36f7cd6f2c37346ee262541 to your computer and use it in GitHub Desktop.
Save isaidamier/624155fdf36f7cd6f2c37346ee262541 to your computer and use it in GitHub Desktop.
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)
...
biometricPrompt = createBiometricPrompt()
promptInfo = createPromptInfo()
...
}
...
private fun createPromptInfo(): BiometricPrompt.PromptInfo {
val promptInfo = BiometricPrompt.PromptInfo.Builder()
// e.g. "Sign in"
.setTitle(getString(R.string.prompt_info_title))
// e.g. "Biometric for My App"
.setSubtitle(getString(R.string.prompt_info_subtitle))
// e.g. "Confirm biometric to continue"
.setDescription(getString(R.string.prompt_info_description))
.setConfirmationRequired(false)
.setNegativeButtonText(getString(R.string.prompt_info_use_app_password))
// .setDeviceCredentialAllowed(true) // Allow PIN/pattern/password authentication.
// Also note that setDeviceCredentialAllowed and setNegativeButtonText are
// incompatible so that if you uncomment one you must comment out the other
.build()
return promptInfo
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment