【问题标题】:Google Play Game Services Sign Out CallbackGoogle Play 游戏服务退出回调
【发布时间】:2016-02-04 23:34:02
【问题描述】:

我正在尝试在我的应用程序中实施 Google Play 游戏服务。我设法让用户在启动时自动登录,并显示排行榜,上传玩家的分数。

我也想处理玩家退出问题。目前,玩家可以从 Google Play 服务排行榜窗口退出。我的问题是如何实现一个接口来检测服务窗口中的用户注销。

http://i.imgur.com/FlAVSbF.jpg

【问题讨论】:

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


    【解决方案1】:

    作为 API 的一部分,没有用于退出的回调。您可以查看GoogleAPIClient.isConnected(),或者如果使用 C++ SDK,请调用 gpg::GameServices::IsAuthorized()

    所以当你显示排行榜时,你可以在 onActivityResult 中查看它们是否已连接。如果不是,则很可能意味着他们已从“设置”菜单中退出。

    public void showLeaderboard()
    {
    startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient,
            LEADERBOARD_ID), REQUEST_LEADERBOARD);
    }
    
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
    
      if (requestCode == REQUEST_LEADERBOARD) {
          // check if user signed out
          mExplicitSignOut = mGoogleApiClient != null && !mGoogleApiClient.isConnected();
      }
      // rest of onActivityResult... 
    }
    

    【讨论】:

      【解决方案2】:

      让我分享另一个解决方案,这在 2019 年似乎更可行:

      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          if (requestCode == RESULT_CODE_GOOGLE_PLAY_GAMES) {
              Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
              try {
                  GoogleSignInAccount account = task.getResult(ApiException.class);
                  // User is signed in
              } catch (ApiException apiException) {
                  // User is signed out
              }
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-05-09
        • 1970-01-01
        • 2014-02-02
        • 1970-01-01
        • 2013-07-31
        • 2017-09-27
        • 2018-05-09
        相关资源
        最近更新 更多