pats pats - 4 months ago 30
Android Question

Increment achievement by achievement in android

My scenario : Lets say I have 3 achievements. I increment 1-achievement, when that is complete I want to increment 2-achievement and so on.

1) How do I switch between achievements and continue increments

2) is there a way to get which achievement I have to increment

3) Is there a way to change the look and feel of 'Games.Achievements.getAchievementsIntent' view?

4) If I want to enable in-app purchases after particular achievement how do I do it?

Thanks

Answer

First Load achievements using
Games.Achievements.load (see Google Play Game Services get achievements list)

Second, loop through all achievements and see all incremental achievements and highest unlocked achievement. Then decide which incremental achievement (achivementId) to increment next.

Finally, use this code to reload achievement when one has been unlocked.

Games.Achievements.incrementImmediate(mGoogleApiClient, achivementId, 1)
                .setResultCallback(new ResultCallback<Achievements.UpdateAchievementResult>() {

                    @Override
                    public void onResult(Achievements.UpdateAchievementResult result) {
                        switch (result.getStatus().getStatusCode()) {
                            case GamesStatusCodes.STATUS_ACHIEVEMENT_UNLOCKED:
                          loadAchievements(); // load achivments and decide which one to increment next
                                 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;
                        }
                    }

                });