【问题标题】:Android Google Play Games API, onActivityResult not calledAndroid Google Play 游戏 API,未调用 onActivityResult
【发布时间】:2015-10-03 17:28:36
【问题描述】:

我最近将新的 play games api 集成到我的应用 WatchStop(下面的链接)中,但我很难管理退出过程。

如果用户从排行榜或成就 UI(Google 的 UI)中退出,则不会在本地退出。调用mGoogleApi.isConnected() 时,GoogleApiClient 仍将报告为已连接。此外,onConnectionFailed()onActivityResult() 都没有被调用,所以我无法知道他们是否已经退出。

我看到有些人在以前版本的 API 中使用 onActivityResult() 取得了成功,但除了来自 Google 的信息之外,还没有找到任何关于使用新 API 的过程的信息:

实现onActivityResult()处理连接解析的结果:

protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == RC_SIGN_IN) { mSignInClicked = false; mResolvingConnectionFailure = false; if (resultCode == RESULT_OK) { mGoogleApiClient.connect(); } else { // Bring up an error dialog to alert the user that sign-in // failed. The R.string.signin_failure should reference an error // string in your strings.xml file that tells the user they // could not be signed in, such as "Unable to sign in." BaseGameUtils.showActivityResultError(this, requestCode, resultCode, R.string.signin_failure); } } }

我以这种方式实现它以尝试监听退出:

@Override public void onActivityResult(int requestCode, int responseCode, Intent intent) { super.onActivityResult(requestCode, responseCode, intent); Toast.makeText(getApplicationContext(), CLASS_NAME + ".onActivityResult() - RESPONSE CODE: " + responseCode + ", REQUEST_CODE: " + requestCode, Toast.LENGTH_LONG).show(); if (requestCode == RC_SIGN_IN && responseCode == RESULT_OK) { mResolvingConnectionFailure = false; if (mGoogleApiClient != null) { mGoogleApiClient.connect(); } } if (responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED && (requestCode == REQUEST_LEADERBOARDS || requestCode == REQUEST_ACHIEVEMENTS)) { mGoogleApiClient.disconnect(); signOutLocal(); } }

上面代码中的 toast 从未显示,向我表明该方法从未被调用。我从中调用的活动扩展了BaseGameActivity(我强制扩展了AppCompatActivity)。我什至尝试覆盖 BaseGameActivity 的 onActivityResult() 以静态调用我的活动中的那个但无济于事(可能是因为它本身没有被称为 idk)。

我可以做些什么来确保如果玩家从 Google 用户界面退出,他们也会在本地退出?如果他们点击“查看排行榜”或“查看成就”而不修复此问题,他们将崩溃,因为在本地,api 仍然认为他们已连接。

【问题讨论】:

    标签: java android google-play-services google-play-games google-plus-signin


    【解决方案1】:

    事实证明,我上面的代码运行良好,但我检查了错误的构建。有兴趣的可以去看看

    responseCode == GamesActivityResultCodes.RESULT_RECONNECT_REQUIRED

    onActivityResult()

    并且您可以知道您不再连接,因此您应该调用您的注销方法。参见上面的 sn-ps。

    【讨论】:

    • 我遇到了同样的问题,并且解决方案按预期工作,但情况并非如此,当用户进入排行榜时选择排行榜并从那里退出。当他回到活动时,responseCode 为 0,而不是 RESULT_RECONNECT_REQUIRED,应用程序崩溃。实际上,当用户在退出后尝试打开另一个排行榜时,排行榜/游戏服务会自行崩溃。使用最新的 GPGS 7.8+ 进行测试。
    • 您提交错误报告了吗?
    • 不,只是崩溃报告。
    猜你喜欢
    • 2014-01-05
    • 1970-01-01
    • 2018-12-14
    • 1970-01-01
    • 1970-01-01
    • 2017-03-11
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多