如何从Google Play游戏服务的排行榜中获得排名? [英] How to get rank from Google Play game service's leaderboard?

查看:152
本文介绍了如何从Google Play游戏服务的排行榜中获得排名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个大型应用程序,我必须从Google Play服务的排行榜中排名玩家.排行榜运作良好.我已经找到了正确的方法,但是我不知道该如何使用它:

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();                
            }
        }
    });
}

但是永远不会调用onResult回调.我应该在哪里调用函数loadRankOfLeaderBoard?我试图将其放在onCreateonActivityResult ...

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...

感谢您的帮助!

推荐答案

好吧,我终于找到了解决方案...

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

因此,如果您遇到相同的问题,则必须将函数loadRankOfLeaderBoard放在函数"onConnected"上,当您在Google Play服务上连接设备时会调用该函数.

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.

这篇关于如何从Google Play游戏服务的排行榜中获得排名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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