简体   繁体   English

用户注销:清除默认的Google帐户不会导致帐户选择器显示在Android应用中

[英]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. 我点击了以下链接,以在使用Google API客户端的android应用中实现“退出”按钮。 However, upon connecting the google api again, the user is not presented with an account picker. 但是,再次连接Google API时,不会向用户显示帐户选择器。 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 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. 使用clearDefaultAccount并尝试重新连接时,我遇到了许多问题。 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). 最后,我决定使用AccountPicker类(顺便说一句,不需要清单中的全局权限)来分离帐户选择过程。

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 ). 因此,当用户想要连接时,请始终显示AccountPicker,然后使用选定的帐户来构建您的GoogleApiClient(请参阅GoogleApiClient.Builder中的.setAccountName )。

Everything works smoothly now. 现在一切正常。

This works for me - use revoke to remove all data in the google client: 这对我有用-使用revoke删除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. 重新连接后的mGoogleApiClient.connect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Google帐户登出并使用Google Drive Android Api再次显示帐户选择器 - how to sign out from Google Account and show account chooser again using Google Drive Android Api 如何使用默认的Google帐户注册GCM而没有帐户选择器选项或任何用户交互android - How to use default google account to register GCM without account picker option or any user interaction android Google登录iOS帐户选择器 - Google Sign-in iOS account picker Foursquare API-如果用户没有帐户,请注册 - Foursquare API - Sign up if user does not have account Google+集成不显示具有单个Google帐户的设备的帐户选择器 - Google+ integration does not show account picker for devices with single google account 使用Android中的Google帐户登录 - Sign in using Google account in Android Android 是否需要 Google 用户帐户? - Does Android require a Google User account? 无法使用 react-native 应用程序在 android 模拟器上登录 Google 帐户 - Could not sign in Google account on android emulator with react-native app Android应用程式内结帐,请登入Google帐户错误 - Android In-App Billing please sign in to Google account error 从Android应用注销Google用户 - Sign out google user from android app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM