4

I'm developing an android app with achievements. Is it possible to know if the achievement is unlocked (or if the goal is reached on incremental ones)?

I've found solutions for old implementations which use Games.Achievements and add a callback function, but it is deprecated. This is the code I'm using for unlocking my achievements:

Games.getAchievementsClient(MyActivity.this, acct).unlockImmediate(my_achievement_id));

I'd like to add a listener to know if after the execution of my code the achievement is unlocked.

1 Answer 1

6

Solved using load method:

Games.getAchievementsClient(MyActivity.this, acct).load(true).addOnSuccessListener(new OnSuccessListener<AnnotatedData<AchievementBuffer>>() {
        @Override
        public void onSuccess(AnnotatedData<AchievementBuffer> achievementBufferAnnotatedData) {
            AchievementBuffer buffer = achievementBufferAnnotatedData.get();
            Achievement achievement;
            Iterator<Achievement> iterator = buffer.iterator();

            while (iterator.hasNext()) {
                achievement = iterator.next();
                if (achievement.getAchievementId().equals(myAchievementId) && achievement.getState() == Achievement.STATE_UNLOCKED) {
                    // The achievement is unlocked
                } else {
                    // The achievement is locked
                }
            }
        }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.