Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listener for Leaderboard in Google game services

I have setup leaderboard using the google game services. I am using the following statement for submitting the statistics after finishing the game.

Games.Leaderboards.submitScore(mHelper.getApiClient(),leaderBoardIdForHits,
totalChanceTaken);

Question :

There may be situation that there will not be the internet services or some failure during the execution of the above submit statement. Also on successful submit of the statistics I need to show a Toast like "Statistics updated". I would like to know if there is any listener method for this.

like image 518
iappmaker Avatar asked Apr 06 '14 16:04

iappmaker


People also ask

How do I add a Google leaderboard?

To create a leaderboard for a new and unpublished game, go to the Google Play Console entry for your game, and navigate to Grow > Play Games Services > Setup and management > Leaderboards, then click the Create leaderboard button.

What is a game leaderboard?

The term leaderboard is often used in the video gaming industry to signify rank among people who play various titles. Players can be ranked against other players based on their number of kills (most common), items collected, or some other metric.


1 Answers

Define this class:

class myLeaderBoardSubmitScoreCallback implements ResultCallback<SubmitScoreResult> {
            @Override
            public void onResult(SubmitScoreResult res) {
                if (res.getStatus().getStatusCode() == 0) {
                    // data sent successfully to server.
                    // display toast.
                }
            }
        }

Then submit your score like this:

Games.Leaderboards.submitScoreImmediate(mHelper.getApiClient(),leaderBoardIdForHits,
totalChanceTaken).setResultCallback(new myLeaderBoardSubmitScoreCallback());

So know when you submit a score, a ResultCallback is set, which is delivered when a leaderboard score has been submitted. And if it has been successfully delivered to the server, display your toast.

like image 59
Ogen Avatar answered Nov 02 '22 09:11

Ogen