Ajitha
Ajitha

Reputation: 239

List all the leaderboards in Google play game services

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?

Upvotes: 14

Views: 3450

Answers (2)

Bolling
Bolling

Reputation: 4083

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
}

Upvotes: 1

Stéphane
Stéphane

Reputation: 1528

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

startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(getApiClient()), REQUEST_LEADERBOARD);

Upvotes: 20

Related Questions