Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - How to get rank from Google Play game service's leaderboard?

I'm working on a big application and I have to take the player's rank from the Google Play services' leaderboard. The leaderboard works well. I've already found the right method but I don't know how I'm supposed to use it:

private void loadRankOfLeaderBoard() {
    Games.Leaderboards.loadCurrentPlayerLeaderboardScore(mGoogleApiClient, getResources().getString(R.string.leaderboard_leaderboard), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
        @Override
        public void onResult(final Leaderboards.LoadPlayerScoreResult scoreResult) {
            if (isScoreResultValid(scoreResult)) {
                rank = (int)scoreResult.getScore().getRank();                
            }
        }
    });
}

But the onResult callback is never called. Where am I supposed to call the function loadRankOfLeaderBoard?? I tried to put it in the onCreate and in the onActivityResult...

Thanks for your help!

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Okay, I finnaly found solution ... here for curious

So if you have the same problem, you have to put the function loadRankOfLeaderBoard on the function "onConnected" which will be call when you connect your device at google play service.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...