通过在android中实现增加成就

时间:2015-05-11 03:37:40

标签: android google-play

我的情景:假设我有3个成就。我增加1成就,当完成时我想增加2成就,依此类推。

1)如何在成就之间切换并继续增量

2)有没有办法获得我必须增加的成就

3)有没有办法改变'Games.Achievements.getAchievementsIntent'视图的外观和感觉?

4)如果我想在特定成就后启用应用内购买,我该怎么做?

由于

2 个答案:

答案 0 :(得分:1)

要做到这一切,你必须创建一个函数,它接受一个如下所示的参数:

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

每当您解锁成就时都要调用此函数。宾果!

答案 1 :(得分:0)

使用
首先加载成就 Games.Achievements.load(见Google Play Game Services get achievements list

其次,循环完成所有成就并查看所有增量成就和最高未锁定成就。然后决定下一步增加哪个增量成就(achivementId)。

最后,使用此代码在解锁时重新加载成就。

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

                });