1

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

pats
  • 1,273
  • 2
  • 20
  • 43

2 Answers2

1

To do all this, you have to make a function which takes one argument like the one given below:

 public boolean unlockAchievement(int whichAchievement)

   {
    switch(whichAchievement)
{
 case 1:

        achievementId = mainActivity.getString(R.string.achievement_id_1);
        achievementCause = mainActivity
                .getString(R.string.achievement_cause_1);
        break;
    case 2:
        achievementId = mainActivity.getString(R.string.achievement_id_2);
        achievementCause = mainActivity
                .getString(R.string.achievement_cause_2);
//Enable inapp purchase here
        break;
  }

    AchievementsClient acClient = mainActivity.agsClient
            .getAchievementsClient();
    AGResponseHandle<UpdateProgressResponse> handle = acClient
            .updateProgress(achievementId, 100.0f);

    // Optional callback to receive notification of success/failure.
    handle.setCallback(new AGResponseCallback<UpdateProgressResponse>() {

        @Override
        public void onComplete(UpdateProgressResponse result) {
            if (result.isError()) {
                // Toast.makeText(mainActivity,
                // "Something is wrong and achievement is not unlocked",
                // Toast.LENGTH_LONG).show();
            } else {
                // Toast.makeText(mainActivity,
                // "Achievement unlocked successfully",
                // Toast.LENGTH_LONG).show();
            }
        }
    });

Call this function whenever you unlock an achievement. Bingo!

Hussein El Feky
  • 6,627
  • 5
  • 44
  • 57
0

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;
                        }
                    }

                });
Community
  • 1
  • 1
pats
  • 1,273
  • 2
  • 20
  • 43