Android排行榜&成就弃用

时间:2018-03-05 13:21:04

标签: android google-play-services deprecated leaderboard achievements

将游戏服务游戏更新至11.8.0后,排行榜和成就已弃用。

1 个答案:

答案 0 :(得分:1)

因为我没有找到关于它的更多信息(遗憾的是没有Stackoverflow主题)。 这是我更新我的代码以使用新的Android文档投诉的方式。

玩家当前的高分:

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

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

显示成就

在11.8.0之前

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

11.8之后:

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

加载成就

在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();

11.8.0之后

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