I am using the new GoogleSignInApi that was introduced in play services 8.3. It remembers the last selected account and doesn't show account picker from 2nd time onwards. But I want it to let user choose account every time. Looks like the clearDefaultAccountAndReconnect() method of GoogleApiClient is not allowed to be used with googleSignInApi. Is there any way to achieve this without implementing a custom account chooser? I am on play services 8.3 and google services 1.5.0.
The account selection is cached, so you have to call signOut first.
-
1mGoogleSignInClient.signOut() worked for me, see (developers.google.com/android/reference/com/google/android/gms/…) – szaske Feb 7 '19 at 18:49
-
@szaske your answer is the correct one. Lol, the most simplest but the most correct! – Jones G Jan 30 at 19:42
-
but this wont work if want to reuse the token for switching account inside our app. – NehaK Feb 15 at 7:17
Call signOut on GoogleApiClinet.
Where ever you are calling this code
Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
Write this code before that.
Auth.GoogleSignInApi.signOut(mGoogleApiClient);
So your new code will look line
Auth.GoogleSignInApi.signOut(mGoogleApiClient);
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
Now it will open popup again & again
-
-
Make sure to connect mGoogleApiClient before calling signOut. Otherwise you'll get
java.lang.IllegalStateException: GoogleApiClient is not connected yet
– RustamG Dec 14 '17 at 5:02 -
thanks @Rahul i was using Auth.GoogleSignInApi.signOut(mGoogleApiClient); at the time of logout only, but your last code calling Auth.GoogleSignInApi.signOut(mGoogleApiClient); before signin did trick for me – Ajeet Choudhary Apr 12 '18 at 5:50
-
Call revokeAccess on GoogleSignInClient
mGoogleSignInClient.revokeAccess();
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(signInIntent, RC_SIGN_IN);
it will show account choose pop up again and again,I hope this will work fine.
GoogleApiClient is not connected
error. I tried callingconnect()
first but doesn't work. Any advice? Could you show an example how did you achive it? Thank you – Gonzalo Mar 28 '17 at 22:18