Search in sources :

Example 1 with CredentialRequest

use of com.google.android.gms.auth.api.credentials.CredentialRequest in project WordPress-Android by wordpress-mobile.

the class SmartLockHelper method smartLockAutoFill.

public void smartLockAutoFill(@NonNull final Callback callback) {
    Activity activity = getActivityAndCheckAvailability();
    if (activity == null || mCredentialsClient == null || !mCredentialsClient.isConnected()) {
        return;
    }
    CredentialRequest credentialRequest = new CredentialRequest.Builder().setPasswordLoginSupported(true).build();
    Auth.CredentialsApi.request(mCredentialsClient, credentialRequest).setResultCallback(new ResultCallback<CredentialRequestResult>() {

        @Override
        public void onResult(@NonNull CredentialRequestResult result) {
            Status status = result.getStatus();
            if (status.isSuccess()) {
                Credential credential = result.getCredential();
                callback.onCredentialRetrieved(credential);
            } else {
                if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
                    try {
                        Activity activity = getActivityAndCheckAvailability();
                        if (activity == null) {
                            return;
                        }
                        // Prompt the user to choose a saved credential
                        status.startResolutionForResult(activity, SignInActivity.SMART_LOCK_READ);
                    } catch (IntentSender.SendIntentException e) {
                        AppLog.d(T.NUX, "SmartLock: Failed to send resolution for credential request");
                    }
                } else {
                    // The user must create an account or log in manually.
                    AppLog.d(T.NUX, "SmartLock: Unsuccessful credential request.");
                }
            }
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) CredentialRequest(com.google.android.gms.auth.api.credentials.CredentialRequest) Credential(com.google.android.gms.auth.api.credentials.Credential) FragmentActivity(android.support.v4.app.FragmentActivity) Activity(android.app.Activity) CredentialRequestResult(com.google.android.gms.auth.api.credentials.CredentialRequestResult)

Aggregations

Activity (android.app.Activity)1 FragmentActivity (android.support.v4.app.FragmentActivity)1 Credential (com.google.android.gms.auth.api.credentials.Credential)1 CredentialRequest (com.google.android.gms.auth.api.credentials.CredentialRequest)1 CredentialRequestResult (com.google.android.gms.auth.api.credentials.CredentialRequestResult)1 Status (com.google.android.gms.common.api.Status)1