Skip to content

Smart Lock For Passwords

Serhii Petrosyuk edited this page Apr 19, 2019 · 6 revisions

Build the SmartLock object

val smartLock = SmartLock.Builder(WeakReference(this))
    .disableAutoSignIn()
    .setAccountTypes(IdentityProviders.GOOGLE, IdentityProviders.FACEBOOK)
    .build()

Request credential and auto-sign in

The requestCredentialAndAutoSignIn() method returns the LiveData object with the AuthResult value type

smartLock.requestCredentialAndAutoSignIn()
    .observe(this, Observer { authResult -> 
        if (it.isSuccess) {
            // Do your stuff with the [authResult.account]
        } else {
            // Handle an error from the [authResult.exceptin]
        }
    })

Save credential

Save the user's Credential by calling the saveCredentials() method

smartLock.saveCredentials(credential)
    .observe(this, Observer { status ->
        // Do your stuff
    })

Request credential

The requestCredential() returns the LiveData object with the CredentialRequestResult value type

smartLock.requestCredential()
    .observe(this, Observer { credentialRequestResult ->
        if (credentialRequestResult.status.isSuccess) {
            // Do your stuff with the [credentialRequestResult.credential]
        } else {
            // Resolve the request result according to the [credentialRequestResult.status]
        }
    })

Delete credential

Delete the user's Credential by calling the deleteCredentials() method

smartLock.deleteCredentials(credential)
    .observe(this, Observer { status ->
        // Do your stuff
    })

this represents the LifecycleOwner