Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
632 views
in Technique[技术] by (71.8m points)

android - GoogleApiClient.isConnected() return always false

I'm trying to implement leaderboard in my game. I wrote 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);

Why mGoogleApiClient.isConnected() returns always false?

EDIT1: Ok, now it works (I have changed 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 works?

EDIT2: I used

startActivityForResult(Games.Leaderboards.getLeaderboardIntent(mGoogleApiClient, "MY_LEADERBOARD_ID"), REQ_LEADERBOARD);

and everything works!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

More reading: http://www.androidpolice.com/2014/02/14/for-developers-google-play-services-4-2-includes-new-client-api-model-consolidates-connections-under-one-object/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...