Integrating Google Play services achievements and android notifications

前端 未结 1 1532
梦如初夏
梦如初夏 2021-01-27 06:19

I am using Google Play services to set up achievements for an android game.

Goal: In my onAchievmentUnlocked callback I want to send a noti

相关标签:
1条回答
  • 2021-01-27 06:52

    Use this code here:

    Games.Achievements.incrementImmediate(GoogleApiClient apiClient, String id, int numSteps)
    .setResultCallback(new  ResultCallback<Achievements.UpdateAchievementResult>() {
    
            @Override
            public void onResult(UpdateAchievementResult result) {
                switch (result.getStatus().getStatusCode()) {
                case GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED:
                    // the state of the achievement is STATE_UNLOCKED after an increment operation. Continuing to increment an already unlocked achievement will always return this status.
                    break;
                case GamesStatusCodes.STATUS_ACHIEVEMENT_UNKNOWN:
                    // the achievement failed to update because could not find the achievement to update.
                    break;
                case GamesStatusCodes.STATUS_ACHIEVEMENT_NOT_INCREMENTAL:
                    // achievement failed to increment since it is not an incremental achievement.
                    break;
                case GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCK_FAILURE:
                    // the call to unlock achievement failed.
                    break;
                }
            }
    
        });
    

    This code will increment an achievement by how many ever steps you want, and then will call onResult to see the status of your achievement that was incremented.

    Here is a link to see more possible statuses: https://developer.android.com/reference/com/google/android/gms/games/achievement/Achievements.UpdateAchievementResult.html

    0 讨论(0)
提交回复
热议问题