Last active
February 22, 2023 16:37
-
-
Save tdcolvin/8345624ead7ded5a134962e94a66d385 to your computer and use it in GitHub Desktop.
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
//Typically you would run this function only after a successful sign-in. No point in saving | |
//credentials that aren't correct. | |
private suspend fun saveCredential(activity: Activity, username: String, password: String) { | |
try { | |
//Ask the user for permission to add the credentials to their store | |
credentialManager.createCredential( | |
request = CreatePasswordRequest(username, password), | |
activity = activity, | |
) | |
Log.v("CredentialTest", "Credentials successfully added") | |
} | |
catch (e: CreateCredentialCancellationException) { | |
//do nothing, the user chose not to save the credential | |
Log.v("CredentialTest", "User cancelled the save") | |
} | |
catch (e: CreateCredentialException) { | |
Log.v("CredentialTest", "Credential save error", e) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment