简体   繁体   中英

Android leaderboard & Achievements deprecate

将游戏服务游戏更新为11.8.0后,排行榜和成就就不再使用了。

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) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM