User Sign-out: clearing the default Google account

2019-05-22 02:13发布

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();
}

3条回答
地球回转人心会变
2楼-- · 2019-05-22 03:00

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

mGoogleApiClient.connect() after reconnecting.

查看更多
姐就是有狂的资本
3楼-- · 2019-05-22 03:02

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.

查看更多
萌系小妹纸
4楼-- · 2019-05-22 03:11

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

查看更多
登录 后发表回答