Smart Lock显示不是来自我的应用程序的帐户

问题描述:

我正在我的应用程序上实现google智能锁,目前,我们仅在应用程序端实现,一旦用户允许保存凭据即可自动登录,例如重新安装. 但是,当我从password.google.com删除密码或在没有为该应用程序存储凭据的设备上运行该应用程序时,该库会显示一个对话框,提示其他网站和应用程序电子邮件.我需要禁用此行为,我只想建议凭据和电子邮件(如果它们属于我的应用程序).

I am implementing google smart lock on my app, for now, we are only implementing on the app side, to log in the user automatically once he allows saving the credentials, on a reinstall for example. But when I removed the password from password.google.com OR when I run the app on a device where the google account doesn't have credentials stored for that app, the library shows a dialog suggesting others sites and apps emails. I need to disable this behavior, I just want to suggest credentials and emails if they belong to my app.

我正在请求使用以下代码的凭据:

I'm requesting credentials with the following code:

    private void requestCredentials() {
            CredentialRequest request = new CredentialRequest.Builder()
                   .setPasswordLoginSupported(true)
                   .setIdTokenRequested(true)
                   .build();
            mProgressSmartLock.show();
    credentialsClient.request(request).addOnCompleteListener(credentialsApiRequestCompleteListener());
    }

和听众:

    public OnCompleteListener<CredentialRequestResponse> credentialsApiRequestCompleteListener(){
            return new OnCompleteListener<CredentialRequestResponse>() {
                @Override
                public void onComplete(@NonNull Task<CredentialRequestResponse> task) {
                // Successfully read the credential without any user interaction, this
                // means there was only a single credential and the user has auto
                // sign-in enabled.
                mProgressSmartLock.dismiss();
                if (task.isSuccessful()) {
                    processRetrievedCredential(task.getResult().getCredential());
                    return;
                }

                    // This is most likely the case where the user has multiple saved
                // credentials and needs to pick one. This requires showing UI to
                // resolve the read request.
                Exception e = task.getException();
                if (e instanceof ResolvableApiException) {
                    ResolvableApiException rae = (ResolvableApiException) e;
                    resolveResult(rae, RC_READ);
                    return;
                }

                // This means only a hint is available
                if (e instanceof ApiException) {
                    Crashlytics.logException(e);
                }
            }
        };
    }

保存凭据:

private void saveCredentials(String email, String password) {
        final Credential credential = new Credential.Builder(email)
                .setPassword(password)
                .build();

        mProgress.show();

        credentialsClient.save(credential).addOnCompleteListener(credentialsApiSaveCompleteListener());
}

听者:

public OnCompleteListener<Void> credentialsApiSaveCompleteListener(){
    return new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if (task.isSuccessful()) {
                mProgress.dismiss();
                return;
            }

            Exception e = task.getException();
            if (e instanceof ResolvableApiException) {
                // The first time a credential is saved, the user is shown UI
                // to confirm the action. This requires resolution.
                ResolvableApiException rae = (ResolvableApiException) e;
                resolveResult(rae, RC_SAVE);
            } else {
                // Save failure cannot be resolved.
                mProgress.dismiss();
            }
        }
    };
}

为避免出现此对话框(该对话框列出了所有电子邮件地址,以帮助填写表单,即使未保存密码也是如此),请不要解决该任务是否getStatusCode()返回SIGN_IN_REQUIRED.

To avoid this dialog (which lists all email addresses in order to help fill a form, even if there is no passwords saved), do not resolve if the task's getStatusCode() returns SIGN_IN_REQUIRED.

抱歉,此详细信息在最近的文档更改中丢失了,感谢您的举报.尽快得到更新,对不起.

Sorry, this detail was lost in a recent doc change, thanks for reporting. Will get that updated ASAP, sorry for the confusion.