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

戏子无情 提交于 2020-02-02 10:32:25

问题


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

回答1:


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.




回答2:


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




回答3:


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

mGoogleApiClient.connect() after reconnecting.



来源:https://stackoverflow.com/questions/26457118/user-sign-out-clearing-the-default-google-account-does-not-cause-the-account-pi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!