GoogleApiClient.isConnected()返回始终为假 [英] GoogleApiClient.isConnected() return always false

查看:823
本文介绍了GoogleApiClient.isConnected()返回始终为假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着在我的游戏排行榜来实现。 我写这篇code:

I try to implement in my game leaderboard. I write this code:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this)
    .addApi(Drive.API)
    .addScope(Drive.SCOPE_FILE)
    .build();

mGoogleApiClient.connect();
//....

while(!mGoogleApiClient.isConnected())Log.d("","NO CONNECTED");
Games.Leaderboards.submitScore(mGoogleApiClient, "MY_LEADERBOARD_ID",newscore);

为什么mGoogleApiClient.isConnected()返回总是假的?

Why mGoogleApiClient.isConnected() return always false?

EDIT1:好了,现在它的工作(我改变Drive.API与Games.API和Drive.SCOPE_FILE与Games.SCOPE_GAME),但是当我称之为submitScore(),即使这一切都OK了日志,该排行榜是仍然是空的。我如何检查是否submitScore()真的管用吗?

Ok, now it work (i change Drive.API with Games.API and Drive.SCOPE_FILE with Games.SCOPE_GAME) but when i call "submitScore()" even if it's all ok in the Log, the leaderboard is still empty. How can i check if "submitScore()" really work?

EDIT2:我用     startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClientMY_LEADERBOARD_ID),REQ_LEADERBOARD); 和一切工作!

I use startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, "MY_LEADERBOARD_ID"), REQ_LEADERBOARD); and everything work!

推荐答案

您需要添加一对夫妇回调监听器的生成器(或GoogleApiClient)。什么是最有可能发生的是,登录失败,因为您没有权限呢。您需要处理的故障,使用户可以授权您的应用程序。

You need to add a couple callback listeners to the Builder (or GoogleApiClient). What's most likely happening is that the login is failing because you don't have permissions yet. You need to handle that failure so that the user can authorize your app.

更多阅读:<一href="http://www.androidpolice.com/2014/02/14/for-developers-google-play-services-4-2-includes-new-client-api-model-consolidates-connections-under-one-object/" rel="nofollow">http://www.androidpolice.com/2014/02/14/for-developers-google-play-services-4-2-includes-new-client-api-model-consolidates-connections-under-one-object/

这篇关于GoogleApiClient.isConnected()返回始终为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆