💾 Retrieve backup

Suppose the user is already enrolled and you have your backup system in place. To retrieve the Keyless backup data and backup key invoke the Keyless.getBackupData() method. You can store the backup data and backup key to let users restore their account with Keyless.
The backup data (type: ByteArray) and backupKey (type: ByteArray) are required to restore an account with Keyless. Save the Keyless backup in a secure data store.
fun retrieveKeylessBackup() {
try {
val backup = Keyless.getBackupData()
val backupData = backup.backupData
val backupKey = backup.backupKey
// Handle your backup system logic
} catch (e: KeylessException) {
// Handle exception

♻️ Restore from backup

Suppose your backup system provided the Keyless backupData and backupKey that was saved when the current user was enrolled. You can invoke the Keyless.enrollFromBackup(backupData: ByteArray, backupKey: ByteArray) method to let the user restore their Keyless data and enroll from backup.
fun enrollFromBackup(backupData: ByteArray, backupKey: ByteArray) {
try {
val backup = Keyless.enrollFromBackup(backupData, backupKey)
} catch (e: KeylessException) {
// Handle exception
As with Keyless.enrollCustomToken() when Keyless.enrollFromBackup() finishes, the enrollmentFinish delegate method gets called. In case of errors, prompt the user to try again.
If the process was successful, stop the loading indicator and navigate to the next screen of your application (e.g. success or main view).
override fun enrollmentFinish(
keylessID: String?,
enrollmentResponse: String?,
error: KeylessException?
) {
// Please make sure to use runOnUiThread() if you need to handle UI changes
if (error != null) {
Log.e(TAG, "Enrollment failed: " + error.title +
" Message: " + error.message + " Code: " + error.code +
" Cancelled by user: " + error.userCancelled);
// Show error alert
// Revert any changes up to this point
// Handle successful enrollment
// At this point the sign up process finished successfully
// Let the user know that signing up was successful and navigate to your next screen like the main screen