Search code examples
javaandroidgoogle-signinautologincredential-manager

[Credential Manager]Automatic login won't select the last account used when multiple Google accounts are present


I'm trying to use Google sign-in, referring to the documentation. https://developer.android.com/identity/sign-in/credential-manager-siwg

The document mentions that calling the "setAutoSelectEnabled(true)" function can achieve automatic login, but I have found that when multiple Google accounts exist and have all been logged in previously, even if the logout function "clearCredentialState()" has been invoked for other accounts, a manual selection of an account is still required for login every time.

Here is the snippet of my code for the automatic login section. enter image description here

Here is my SDK version. enter image description here

Does anyone have a better solution?

I would like to know if it can automatically select and log in with the account that was not logged out last time, or directly obtain the previously logged-in idtoken to replace the automatic login process.


Solution

  • If there are more than one Google accounts that have the grants for your app (that is, user had previously used both of them to sign into your app), then we do not pick any in favor of the other one since we don't know which one user really wants to use (since both have been used in the past), hence we do not do an auto sign-in.