java.lang.IllegalStateException:GoogleApiClient尚未连接

Fab*_*ues 5 java android achievements google-play

我正在尝试使用Google Play游戏服务为我的游戏添加成就.我的游戏中负责提供成就的活动已经扩展了BaseGameActivity,当它必须给出成就时它调用beginUserInitiatedSignIn,因此用户必须登录,但是当我解锁用户的成就时,我保持得到"java.lang.IllegalStateException:GoogleApiClient尚未连接".谁能告诉我我做错了什么?这是负责解锁成就的代码(它来自BaseGameUtils扩展BaseGameActivity的类):

private void darConquistaDerrubouArvore(int numeroDeAcertos) {
     // start the asynchronous sign in flow
    mSignInClicked = true;
    mGoogleApiClient.connect();
    if(numeroDeAcertos <= 40)
    {
        try
        {
                beginUserInitiatedSignIn();
                Games.Achievements.unlock(gameHelper.getApiClient(), "CgkIs_27xcoSEAIQAQ");
                Log.i("TelaModoCasual", "usuário não está logado");
                this.onSignInFailed();

        }
        catch(Exception exc)
        {
            exc.printStackTrace();
            this.onSignInFailed();
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

Cla*_*son 2

查看基本示例https://github.com/playgameservices/android-basic-samples/tree/master/BasicSamples/TypeANumber。Google API 的连接流是异步的,因此您无法解锁已有的成就。一旦建立连接,就会调用 onConnected() 回调。通过这种方法,您可以解锁成就。

api 客户端的文档位于http://developer.android.com/google/auth/api-client.html