四年之后,我遇到了与这种情况类似的问题。一些东西已经被弃用了,而一些东西不再起作用。因此,对于那些想要知道如何在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(社交集合)。