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

早过忘川 提交于 2019-12-08 22:35:10

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/37610936/how-to-get-rank-from-google-play-game-services-leaderboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!