List all the leaderboards in Google play game services
Asked Answered
H

2

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?

Hydrotherapy answered 24/2, 2014 at 16:32 Comment(0)
T
20

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

startActivityForResult(Games.Leaderboards.getAllLeaderboardsIntent(getApiClient()), REQUEST_LEADERBOARD);
Toile answered 24/2, 2014 at 21:18 Comment(2)
The request code REQUEST_LEADERBOARD is an arbitrary integer that you define by yourself.Tien
It is deprecated now.Swampland
S
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
}
Swampland answered 26/6, 2020 at 6:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.