简体   繁体   中英

User Sign-out: clearing the default Google account does not cause the account picker to show up in Android app

I followed the below link to implement a "sign out" button in my android app, which uses a Google API client. However, upon connecting the google api again, the user is not presented with an account picker. It looks like the value of her/his original choice is somehow still cached perhaps. I've been trying to figure this out for a few hours.

Any and all ideas very welcome. Thank you.

https://developers.google.com/+/mobile/android/sign-in

if (mGoogleApiClient.isConnected()) {
  Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
  mGoogleApiClient.disconnect();
}

I've had many problems using clearDefaultAccount and trying to reconnect as well. Finally I've decided to separate the account selection process by using the AccountPicker class (which, by the way, doesn't require global permissions in manifest).

So, when the user wants to connect, always show the AccountPicker and then use the selected account to build your GoogleApiClient (see .setAccountName in GoogleApiClient.Builder ).

Everything works smoothly now.

This works for me - use revoke to remove all data in the google client:

public void logout()
{
    if (mPlusClient.isConnected())
    {
        Plus.AccountApi.clearDefaultAccount(mPlusClient);
        Plus.AccountApi.revokeAccessAndDisconnect(mPlusClient);
    }
}

Afterwards, if you try to login again, you'll be presented an account selector again

You are not being presented with an account picker because you didn't call

mGoogleApiClient.connect() after reconnecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM