Mathoa
Mathoa

Reputation: 143

Android leaderboard & Achievements deprecate

After updating play-services-games to 11.8.0, Leaderboard and Achievements became deprecate.

Upvotes: 1

Views: 922

Answers (1)

Mathoa
Mathoa

Reputation: 143

Since I did not find much info about it (and sadly no Stackoverflow topic). This is how I updated my code to be complaint with the new Android documentation.

Current high score for player:

before 11.8.0:

Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(), leaderboard, highscoretime[scoreLevel], LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(
                    new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
                        @Override
                        public void onResult(Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
                            if (GamesStatusCodes.STATUS_OK == loadPlayerScoreResult.getStatus().getStatusCode()) {
                                if (loadPlayerScoreResult.getScore() != null) {

After 11.8:

Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this))
                    .loadCurrentPlayerLeaderboardScore(leaderboard, highscoretime[scoreLevel], LeaderboardVariant.COLLECTION_PUBLIC)
                    .addOnSuccessListener(new OnSuccessListener<AnnotatedData<LeaderboardScore>>() {
                                              @Override
                                              public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
                                                  if (leaderboardScoreAnnotatedData != null) {
                                                      if (leaderboardScoreAnnotatedData.get() != null) {

Displaying Achievements:

before 11.8.0:

startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), RC_REQUEST_ACHIEVEMENTS);

after 11.8:

Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))
            .getAchievementsIntent()
            .addOnSuccessListener(new OnSuccessListener<Intent>() {
                @Override
                public void onSuccess(Intent intent) {
                    startActivityForResult(intent, RC_REQUEST_ACHIEVEMENTS);
                }
            });

Load Achievments

before 11.8.0

private class AchievementClass implements ResultCallback<Achievements.LoadAchievementsResult> {
    @Override
    public void onResult(@NonNull Achievements.LoadAchievementsResult arg0) {
        try {
            AchievementBuffer aBuffer = arg0.getAchievements();
            Iterator<Achievement> aIterator = aBuffer.iterator();
            while (aIterator.hasNext()) {
                Achievement ach = aIterator.next();

after 11.8.0

Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))
    .load(true).addOnSuccessListener(new OnSuccessListener<AnnotatedData<AchievementBuffer>>() {
        @Override
        public void onSuccess(AnnotatedData<AchievementBuffer> achievementBufferAnnotatedData) {

Upvotes: 4

Related Questions