Last active
November 24, 2022 16:32
-
-
Save GBouerat/9870468 to your computer and use it in GitHub Desktop.
Increment current player leaderboard score on Google Play Game Services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
}); | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you