Skip to content

Instantly share code, notes, and snippets.

@GBouerat
Last active November 24, 2022 16:32
Show Gist options
  • Save GBouerat/9870468 to your computer and use it in GitHub Desktop.
Save GBouerat/9870468 to your computer and use it in GitHub Desktop.
Increment current player leaderboard score on Google Play Game Services
public class GameActivity extends BaseGameActivity {
...
private static void updateLeaderboards(final GoogleApiClient googleApiClient, final String leaderboardId) {
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(
googleApiClient,
leaderboardId,
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC
).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
if (loadPlayerScoreResult != null) {
if (GamesStatusCodes.STATUS_OK == loadPlayerScoreResult.getStatus().getStatusCode()) {
long score = 0;
if (loadPlayerScoreResult.getScore() != null) {
score = loadPlayerScoreResult.getScore().getRawScore();
}
Games.Leaderboards.submitScore(googleApiClient, leaderboardId, ++score);
}
}
}
});
}
...
}
@NunciosChums
Copy link

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment