问题描述
我正在我的应用程序中实现Google Smart Lock.我已经用一个帐户自动将用户登录,并且效果很好.
I'm implementing Google Smart Lock into my app. I've got it logging the user in automatically with a single account and it works well.
但是,一旦我在组合中添加了第二个帐户,它始终会显示解决方案对话框以选择我想要的帐户.即使我选择了帐户并重新启动应用程序后,该消息仍会继续显示.
However, once I add a second account to the mix it always shows the resolution dialog to pick which account I want. This continues to show even after I have selected and account and restarted the app.
选择我要使用智能锁的帐户后,该对话框将不再显示,那么仍然显示该对话框的可能原因有哪些?
This dialog shouldn't show anymore once I have selected the account I want smart lock to use, so what are some possible reasons for it still showing?
-谢谢
推荐答案
我在Google的Smart Lock团队工作,希望可以回答您的问题:
I work on the Smart Lock team at Google, hopefully this answers your question:
-
,请注意,如果调用
CredentialsApi.request()
API方法,并且该应用有多个保存的帐户,则存储在设备上的一个或多个Google帐户中(或用户已通过调用CredentialsApi.disableAutoSignIn()
)禁用了其帐户之一的自动登录或由开发人员禁用,则API将使用CredentialRequestResult
,其中getStatusCode()
为RESOLUTION_REQUIRED
,这意味着必须显示UI,以便用户选择凭据才能继续.startResolutionForResult()
将显示对话框,如中所述API概述.
as you note, if the
CredentialsApi.request()
API method is called and there are multiple saved accounts for the app, stored in either one or multiple Google Accounts on the device (or auto sign-in has been disabled by the user for one of their accounts or by the developer by callingCredentialsApi.disableAutoSignIn()
) then the API will call back with aCredentialRequestResult
withgetStatusCode()
ofRESOLUTION_REQUIRED
, meaning that UI must be shown for the user to pick a credential to continue.startResolutionForResult()
will show the dialog, as described in the API overview.
一旦应用具有自动登录或用户从对话框中选择一个凭据后,大多数应用将使用该凭据将用户登录到后端服务并与之建立会话应用程序的Cookie或令牌,并独立于Smart Lock API进行管理.因此,大多数应用程序在用户登录并存在当前会话后将不会再次调用API,因此在初始登录后将不会再次显示该对话框.
once the app has a credential, either from auto sign-in or after the user has selected one from the dialog, most apps will use this credential to sign the user in to a backend service and establish a session with a cookie or token for the app and manage this independent of the Smart Lock API. Thus, most apps won't call the API again after the user has signed in and a current session exists, hence the dialog won't be shown again after the initial sign-in.
当用户注销时,调用 CredentialsApi.disableAutoSignIn()
将阻止用户在再次启动身份验证活动时自动重新登录,并自动管理禁用状态并在用户从凭据选择器UI中选择条目或成功进行 CredentialsApi.save()
调用时清除,并且此时,用户会话已建立,无需调用再次使用API,直到退出事件为止.
when the user signs out, calling CredentialsApi.disableAutoSignIn()
will prevent the user from being automatically signed back in when the authentication activity is started again, and the disabled state is automatically managed and cleared when the user selects an entry from the credential picker UI or a successful CredentialsApi.save()
call is made, and at this point, a user session is established and there is no need to call the API again until a sign-out event.
我认为这个问题的困惑来自用户登录后调用API,并且他们可能已经处于活动状态.那是你的意图吗?如果在用户检索或输入密码后需要在设备上管理应用程序的凭据,则可以使用帐户管理器,它独立于任何Google帐户或API(而Smart Lock旨在将登录信息保存在云中,以便在新的或单独的平台上跨平台使用设备以引导身份验证过程.
I think the confusion in this question stems from calling the API after the user has signed in and they might already have an active session. Was that your intent? If you need to manage credentials of the app on the device after a password has been retrieved or input by the user, you can use the Account Manager on Android, which is independent of any Google accounts or APIs (whereas Smart Lock is geared toward saving sign-in info in the cloud for use across platforms on new or separate devices to bootstrap the auth process).
将来,如果存储了多个帐户并且总是选择相同的帐户,那么我们正在考虑记住用户的偏好,从而可以自动登录,但是现在,当有多个保存的帐户可用时,总是需要用户采取行动
In the future, we are considering remembering a user preference if multiple accounts are stored and the same one is always picked, thereby allowing automatic sign-in, but right now, user action is always required when there are multiple saved accounts available.
如果您需要更多信息或说明,或者没有回答您的问题,请留下任何问题或反馈的评论!
Do leave a comment with any questions or feedback if you need more info or clarification or if this doesn't answer your question!
这篇关于Smart Lock多帐户解决方案始终显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!