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