Search code examples
javalibgdxgoogle-playgoogle-play-services

Google Api Client interface methods explanation?


    @Override
public void getLeaderboardGPGS() {
    if (gameHelper.isSignedIn()) {
        startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), getString(R.string.event_score)), 100);
    }
    else if (!gameHelper.isConnecting()) {
        loginGPGS();
    }
}

@Override
public void getAchievementsGPGS() {
    if (gameHelper.isSignedIn()) {
        startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), 101);
    }
    else if (!gameHelper.isConnecting()) {
        loginGPGS();
    }
}

Can anyone explain to me what these methods do? I have them as part of implementing a GoogleApi interface I made in the context of a tutorial. I especially don't understand the 100 / 101 parts, but the whole thing, in general, is quite confusing for me.

PS. I am making a game in LibGDX and this is my first time touching the Google Play API (or I think any API for that matter)


Solution

  • First Method getLeaderboardGPGS show you Leaderboard above your Activity if you are already Signed in otherwise it start signing process.

    Above method definition is from Libgdx wiki but it should be

    private final static int REQUEST_CODE_UNUSED = 9002;
    
    startActivityForResult(Games.Leaderboards.getLeaderboardIntent(gameHelper.getApiClient(), getString(R.string.leaderboardId)), REQUEST_CODE_UNUSED);
    

    REQUEST_CODE_UNUSED is an arbitrary integer for the request code getString(R.string.leaderboardId) is LEADERBOARD_ID

    taken from Google wiki

    Second Method getAchievementsGPGS is used to show a player's achievements, call getAchievementsIntent() to get an Intent to create the default achievements UI.

    startActivityForResult(Games.Achievements.getAchievementsIntent(gameHelper.getApiClient()), REQUEST_ACHIEVEMENTS);
    

    where REQUEST_ACHIEVEMENTS is an arbitrary integer used as the request code.