4 年后,我遇到了类似的问题。有些东西已被弃用,有些东西不再有效。因此,对于那些现在想知道如何做的人,在 2018 年......检查这个答案-
首先你必须得到 LeaderBoardClient
mLeaderboardsClient = Games.getLeaderboardsClient(MainActivity.this, googleSignInAccount);
接下来就可以得分了
mLeaderboardsClient.loadCurrentPlayerLeaderboardScore(getString(R.string.leaderboard_id), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC)
.addOnSuccessListener(this, new OnSuccessListener<AnnotatedData<LeaderboardScore>>() {
@Override
public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
long score = 0L;
if (leaderboardScoreAnnotatedData != null) {
if (leaderboardScoreAnnotatedData.get() != null) {
score = leaderboardScoreAnnotatedData.get().getRawScore();
Toast.makeText(MainActivity.this, Long.toString(score), Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: " + Long.toString(score));
} else {
Toast.makeText(MainActivity.this, "no data at .get()", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: .get() is null");
}
} else {
Toast.makeText(MainActivity.this, "no data...", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: " + Long.toString(score));
}
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(MainActivity.this, "Failure", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: FAILURE");
}
});
.loadCurrentPlayerLeaderboardScore的3个参数如下
排行榜的 ID,从中加载分数。
时间跨度来检索数据。有效值为 TIME_SPAN_DAILY、TIME_SPAN_WEEKLY 或 TIME_SPAN_ALL_TIME。
排行榜集合来检索分数。有效值为 COLLECTION_PUBLIC 或 COLLECTION_SOCIAL。