Huawei Game Service & Map Kit & Account Kit (İl Bil Sample App) — Part 3

Gökhan YILMAZ
Huawei Developers
Published in
4 min readMay 6, 2021

Before you start, make sure to checkout previous parts of this article.

Huawei Game Service

Leaderboard Feature

Leaderboards are an effective way to drive competition among game players by displaying players’ rankings. You can create up to 70 leaderboards in AppGallery Connect.

Create Leaderbord on AGC

  • Name: Name of a leaderboard.
  • Score format: You can define the score format as any of the following when creating a leaderboard: Currency, Time, Numeric.
  • Icon: Icon associated with a leaderboard.
  • Ordering: Ordering mode of leaderboard entries. You can define whether a larger or smaller score is better.
  • Limits: Lower and upper limits of scores allowed by a leaderboard.
  • List order: Order of a leaderboard among all leaderboards. You need to set this attribute when creating a leaderboard.

When the Leaderboard approved from Huawei reviewer, the screen should be like image above.

Initialize Leaderboard

When the Game Fragment ready, we are calling initGameService() function. The function, calls gameService.initialize() method for preparing RankingClient object.

In the initialize() function, initialize JosAppClient object and prepare RankingClient object for submit score and show Leaderboard via Huawei Game Service.

Submit Score to Specific Leaderboard

When user finish the game, we must send game score to Huawei Leaderboard.

In this case, firstly we must change user’s ranking status as 1. I will give more information on that below. And then we can send the score to Huawei Leaderboard.

So, I call gameService.rankingSwitchStatus(), gameService.submitScoreWithResult() methods in this order.

This is a simple function. I’m just callling rankingClient.setRankingSwitchStatus(stateValue). So now we can send user’s score to the Huawei Leaderboard. By the way the stateValue’s value is 1.

More detail about Rankins Switch Status:

Also you need more detail, click here.

When RankingSwitchStatus value is 1, we can send user’s game score via submitScoreWithResult() method. The method has 2 params. LEADERBOARD_ID’s value is on AGC, score’s value is user’s game score.

There is no need handle the task is successful or not in my game scenario.

Show Leaderboard via HUAWEI AppAssistant

However, you need to ensure that your player’s device is running EMUI 10.0 or later and has installed HUAWEI AppAssistant 10.1 or later. Currently, not all Huawei devices support this function.

When user click the btnLeaderBoard button, we have to call gameService.obtainLeaderBoard() method and than in onSuccess block it is calling startActivityResult() function and app shows Leaderboard via HUAWEI AppAssistant.

On the obtainLeaderBoard() function, we are calling rankingClient.totalRankingIntent for getting Leaderboard intent. If intent is not null, onSuccess.invoke() will be called.

--

--