我正在尝试通过使用Google Play游戏服务向我的游戏添加成就。负责给予成就的游戏活动已经扩展了BaseGameActivity,并在必须给予成就时调用beginUserInitiatedSignIn,因此用户必须登录,但是在我为用户解锁成就时,我一直收到“java.lang.IllegalStateException: GoogleApiClient is not connected yet”的错误。有人可以告诉我我做错了什么吗?以下是解锁成就的代码(它在扩展BaseGameActivity的类中,来自BaseGameUtils):
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();
}
}
}