Earning user points from Google Play Game Services?

I am new to Android app development. I want to get the user's rating from the Google Play Game service, and I use the following code to get a high score, but I don’t have any knowledge about how it returns the value and how to save it.

Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(), getString(R.string.highscore), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC);

Saving it to int or string does not work.

+4
source share
2 answers

Method:

loadCurrentPlayerLeaderboardScore (GoogleApiClient apiClient, String leaderboardId, int span, int leaderboardCollection)

returns

PendingResult<Leaderboards.LoadPlayerScoreResult>

Then you must use the getScore()class method Leaderboards.LoadPlayerScoreResultto get it.

Please view these links ...

LoadCurrentPlayerLeaderboardScore Method

LoadPlayerScoreResult in PendingResult

EDIT: Here you can use it.

Games.Leaderboards.loadCurrentPlayerLeaderboardScore().setResultCallback(new ResultCallback<LoadPlayerScoreResult>() {

            @Override
            public void onResult(LoadPlayerScoreResult arg0) {
                LeaderboardScore c = arg0.getScore();
            }

        });

This is how you get the grade.

+6

loadCurrentPlayerLeaderboardScore

     Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(),
            getString(R.string.word_attack_leaderboard),
            LeaderboardVariant.TIME_SPAN_ALL_TIME,
            LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(
            new ResultCallback<LoadPlayerScoreResult>() {

                @Override
                public void onResult(LoadPlayerScoreResult arg0) {
                    LeaderboardScore c = arg0.getScore();
                    long score = c.getRawScore();
                }
             }

R.string.word_attack_leaderboard - , google

+7

Source: https://habr.com/ru/post/1531287/


All Articles