Search code examples
androidlibgdxgoogle-playgoogle-play-servicesgoogle-play-games

Google Play Game Services Sign Out Callback


I am trying to implement Google Play Game Services to my application. I managed to get user to sign in automaticlly on launch, and show leaderboards, upload player's score.

I want to handle player sign out as well. Curently, player can sign out from Google Play Services Leaderboard window. My question is how to implement an interface to detect the user logout from Services window.

https://i.sstatic.net/Kfmg7.jpg


Solution

  • There is no callback for signing out that is part of the API. You can check the GoogleAPIClient.isConnected(), or if using the C++ SDK, call gpg::GameServices::IsAuthorized()

    So when you show the leaderboard, you can check in onActivityResult to see if they are connected. If they are not, it most likely means they signed out from the Settings menu.

    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... 
    }