无法在Android中解锁成就

时间:2014-08-08 13:10:40

标签: android

我正在尝试构建一个有5个成就的游戏: - 简单 - 正常 - 中等 - 很难 - 提前

但是为什么我无法通过以下代码解锁成就:

Games.Achievements.unlock(getApiClient(), getString(R.string.achievement_easy));

但我可以通过以下代码很好地展示所有成就:

startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), REQUEST_ACHIEVEMENTS);

和 我也可以通过以下代码将得分插入排行榜:

Games.Leaderboards.submitScore(getApiClient(), getString(R.string.leaderboard_easy), inScore);

尝试解锁成就时的CatLog:

08-08 14:47:33.513: W/dalvikvm(25551): threadid=1: thread exiting with uncaught exception (group=0x417fac08)
08-08 14:47:33.518: E/AndroidRuntime(25551): FATAL EXCEPTION: main
08-08 14:47:33.518: E/AndroidRuntime(25551): Process: kids.math.newmathforkids, PID: 25551
08-08 14:47:33.518: E/AndroidRuntime(25551): java.lang.RuntimeException: Unable to start activity ComponentInfo{kids.math.newmathforkids/kids.math.newmathforkids.update_score}: java.lang.IllegalStateException: GoogleApiClient is not connected yet.
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2394)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2452)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.ActivityThread.access$900(ActivityThread.java:172)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1302)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.os.Handler.dispatchMessage(Handler.java:102)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.os.Looper.loop(Looper.java:136)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.ActivityThread.main(ActivityThread.java:5586)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at java.lang.reflect.Method.invokeNative(Native Method)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at java.lang.reflect.Method.invoke(Method.java:515)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at dalvik.system.NativeStart.main(Native Method)
08-08 14:47:33.518: E/AndroidRuntime(25551): Caused by: java.lang.IllegalStateException: GoogleApiClient is not connected yet.
08-08 14:47:33.518: E/AndroidRuntime(25551):    at com.google.android.gms.internal.hn.a(Unknown Source)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at com.google.android.gms.common.api.c.b(Unknown Source)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at com.google.android.gms.games.internal.api.AchievementsImpl.unlock(Unknown Source)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at kids.math.newmathforkids.update_score.onCreate(update_score.java:261)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.Activity.performCreate(Activity.java:5451)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
08-08 14:47:33.518: E/AndroidRuntime(25551):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2358)
08-08 14:47:33.518: E/AndroidRuntime(25551):    ... 11 more

的活动:

public class Acs extends BaseGameActivity {
    protected static final int REQUEST_LEADERBOARD = 0;
    protected static final int REQUEST_ACHIEVEMENTS = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.score_update);

    TextView show_achievement = (TextView) findViewById(R.id.show_achievement_level);
    show_achievement.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
              // TODO Auto-generated method stub
               startActivityForResult(Games.Achievements.getAchievementsIntent(getApiClient()), REQUEST_ACHIEVEMENTS);
           }
        });

   String total_score_easy_level = s1.getText().toString();
   int score_easy = Integer.parseInt(total_score_easy_level);
   if(score_easy > 100)
        {
            Games.Achievements.unlock(getApiClient(), getString(R.string.achievement_easy));
        }
}

@Override
public void onSignInFailed() {
    // TODO Auto-generated method stub
    Log.d("sigin failed", "inside on onSignInFailed");
}
@Override
public void onSignInSucceeded() {
    // TODO Auto-generated method stub
    Log.d("sigin succeded", "inside on onSignInSucceeded");
    //subMitScore();
}
}

任何人都可以帮我解决这个问题吗?

最诚挚的问候,

1 个答案:

答案 0 :(得分:1)

根据您的错误,我认为您的google api客户端设置不正确。请务必遵循this guide from google's documentation step by step