问题
I have integrated Google Leaderboard in my android game app. When I open it, it goes to "Social" mode by default (aka my Google circle). I need to manually switch to "All" mode (players from all around the world). How can I make "All" mode default?
回答1:
There is an overloaded method that takes all the parameters: getLeaderboardIntent (GoogleApiClient apiClient, String leaderboardId, int timeSpan, int collection)
You can get the intent and display the all leaderboard by:
Intent intent = Games.Leaderboards.getLeaderboardIntent(apiClient,
leaderboardId, LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC);
// REQUEST_LEADERBOARD is an arbitrary constant to check for in onActivityResult
activity.startActivityForResult(intent, REQUEST_LEADERBOARD);
For more information see: https://developers.google.com/games/services/android/leaderboards#displaying_a_leaderboard
回答2:
Based on google documentation the below answer from Clayton looks perfect. However I think there is a mismatch between google documentation and Leaderboard class.
If you try : Games.Leaderboards.getLeaderboardIntent(GoogleApiClient apiClient, String leaderboardId)
it works.
If you try : Games.Leaderboards.getLeaderboardIntent(GoogleApiClient apiClient, String leaderboardId, int timeSpan)
it works but whatever the int value you will have an Leaderboard on "All time" based.
If you try (what should be your anwser): Games.Leaderboards.getLeaderboardIntent(GoogleApiClient apiClient, String leaderboardId, int timeSpan, int collection)
it doesn't work (the method doesn't exist).
To illustrate what I mean by "doesn't exist" you can have a look at what should be our Leaderboard
class (lines between 49 and 51) :
https://github.com/gamea-fiks/ccc/blob/62156a697da41733afb23a63beed05e3b17a5784/sources/com/google/android/gms/games/leaderboard/Leaderboards.java
Another question on Stackoverflow is also about this problem : https://stackoverflow.com/questions/32867659/how-to-show-public-collection-from-google-leaderboard-with-getleaderboardintent
By the way let's hope it will be corrected soon (or that I am wrong somewhere) !
来源:https://stackoverflow.com/questions/37415206/how-to-open-all-by-default-instead-of-social-in-google-leaderboard