繁体   English   中英

java.lang.IllegalStateException:GoogleApiClient尚未连接

[英]java.lang.IllegalStateException: GoogleApiClient is not connected yet

我正在尝试使用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();
        }
    }

}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM