android - 如何避免再次提示用户选择 Google 帐户?

标签 android google-play-services google-play-games

我正在使用 Google Play Games Services 开发 Android 应用程序,并且我遵循了 getting started guide通过将 BaseGameUtils 作为模块导入到我的 IntelliJ 项目中。这现在工作正常,除了每当我打开一个继承 BaseGameActivity 的 Activity 并调用 beginUserInitiatedSignIn() 时,系统会提示用户选择要连接的 Google 帐户(如果更多比一个人在电话里)。现在,如果不是因为在我的应用程序中,用户已经通过 Google Play 服务获得授权,这会很好 using OAuth2 ( GoogleAuthUtil/AccountPicker )。它已经给出了他/她想要使用的帐户 - 不需要再问一次。

我是否可以修改 BaseGameActivity.javaGameHelper.java 以便不再提示用户?和/或我是否需要更改使用 OAuth2 登录的方式?

我已经尝试将四个范围 PLUS_PROFILE、PLUS_LOGIN、GAMES 和 APP_STATE 添加到我的 OAuth 登录例程中,但是 AccountPicker-popup 窗台出现在我继承自 BaseGameActivity 的 Activity 中。

更新:Logcat-log

07-23 11:45:25.275: DEBUG/CSDN-GMS(22315): isGooglePlayServicesAvailable returned 0
07-23 11:45:25.275: DEBUG/CSDN-GMS(22315): beginUserInitiatedSignIn: starting new sign-in flow.
07-23 11:45:25.285: DEBUG/CSDN-GMS(22315): Connecting GamesClient.
07-23 11:45:25.295: DEBUG/CSDN-GMS(22315): onStart.
07-23 11:45:25.295: DEBUG/CSDN-GMS(22315): onStart: connecting clients.
07-23 11:45:25.295: DEBUG/CSDN-GMS(22315): Connecting GamesClient.
07-23 11:45:25.395: DEBUG/CSDN-GMS(22315): onConnectionFailed: result 4
07-23 11:45:25.395: DEBUG/CSDN-GMS(22315): onConnectionFailed: since user initiated sign-in, trying to resolve problem.
07-23 11:45:25.395: DEBUG/CSDN-GMS(22315): resolveConnectionResult: trying to resolve result: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{4190b780: android.os.BinderProxy@4190a780}}
07-23 11:45:25.395: DEBUG/CSDN-GMS(22315): result has resolution. Starting it.

最佳答案

您需要先使用 OAuth2 登录,还是可以先登录 Google Games?如果您可以先登录 Google Games,则可以使用 GamesClient.getCurrentAccountName()。来自 https://developer.android.com/reference/com/google/android/gms/games/GamesClient.html#getCurrentAccountName() :

Get the name of the currently selected account. This is the account the user has chosen to use for Google Play Games.

然后您可以将该帐户选择提供给 OAuth2 身份验证。

关于android - 如何避免再次提示用户选择 Google 帐户?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17701504/

相关文章:

android - 如何显示我的应用程序中的结果对话框(例如Google Play游戏)

android - 更改compileSDK版本时如何解决android支持库的问题?

android - 如何删除三个按钮之间的空格

android - 在我的应用程序中,我没有收到 Moto G 第三代 Android 6.0 移动设备中位置对象的速度

android - 我们可以在 PlayStore 付款之前在付费应用上安装时显示协议(protocol)弹出窗口吗

android - Unity Google Play Services Plugin API 与 Show Leaderboard UI 功能不同步?

android - LeakCanary有回调吗?

android - 交互式安卓动画

android - Plus.PeopleApi.getCurrentPerson 在 Play 服务 8.4 中已弃用。如何使用 GoogleSignInApi 获取用户的名字、姓氏和性别?

c# - Unity 中基于 Google Games Services 回合制多人游戏的自定义 UI