14

In the documentation the code snippet to display leaderboard is

startActivityForResult(Games.Leaderboards.getLeaderboardIntent(getApiClient(), LEADERBOARD_ID), REQUEST_LEADERBOARD);

This goes into the given leaderboard with LEADERBOARD_ID

My game has severel leaderboards and what I want to do is display a list of them so that user can select a specific leaderboard.

Is it possible to do that?

King of Masses
  • 18,405
  • 4
  • 60
  • 77
Ajitha
  • 239
  • 3
  • 10

2 Answers2

20

If you want to use the default UI, you can use this:

startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(getApiClient()), REQUEST_LEADERBOARD);
tom.dietrich
  • 8,219
  • 2
  • 39
  • 56
Stéphane
  • 1,518
  • 1
  • 18
  • 31
1

This is the new way of doing it:

Games.getLeaderboardsClient(this, GoogleSignIn.getLastSignedInAccount(this)!!)
                    .allLeaderboardsIntent
                    .addOnSuccessListener { intent ->
                        startActivityForResult(
                            intent,
                            RC_LEADERBOARD_UI
                        )
                    }

companion object{
    private const val RC_LEADERBOARD_UI = 9004
}
Bolling
  • 3,954
  • 1
  • 27
  • 29