目录

The RankingsClient class defines the APIs related to leaderboards, for example, APIs for obtaining leaderboard data and setting the leaderboard switch.

Public Method Summary

Return

Method

Task<Intent>

getTotalRankingsIntent()

Obtains the Intent object of the leaderboard list screen.

Task<Intent>

getRankingIntent(String rankingId, int   timeDimension)

Obtains the Intent object of the screen for a specified leaderboard in a specified time frame.

Task<Intent>

getRankingIntent(String rankingId)

Obtains the Intent object of the screen for a specified leaderboard in all time frames.

Task<RankingScore>

getCurrentPlayerRankingScore(String rankingId, int timeDimension)

Obtains the score of a player on a specified leaderboard in a specified time frame.

Task<List<Ranking>>

getRankingSummary(boolean isRealTime)

Obtains all leaderboard data. The data can be obtained from the local cache.

Task<Ranking>

getRankingSummary(String rankingId,  boolean isRealTime)

Obtains the data of a leaderboard. The data can be obtained from the local cache.

Task<RankingsClient.RankingScores>

getMoreRankingScores(String rankingId,long offsetPlayerRank, int maxResults, int pageDirection, int timeDimension)

Obtains scores on a leaderboard in a specified time frame in pagination mode.

Task<RankingsClient.RankingScores>

getPlayerCenteredRankingScores(String   rankingId, int timeDimension, int maxResults, boolean isRealTime)

Obtains scores of a leaderboard with the current player's score displayed in the center. The data can be obtained from the local cache.

Task<RankingsClient.RankingScores>

getPlayerCenteredRankingScores(String rankingId, int timeDimension,int maxResults, long offsetPlayerRank, int pageDirection)

Obtains scores of a leaderboard with the current player's score displayed in the center from Huawei game server.

Task<RankingsClient.RankingScores>

getRankingTopScores(String rankingId, int timeDimension, int maxResults, long offsetPlayerRank, int pageDirection)

Obtains the scores on the first page of a leaderboard from Huawei game server.

Task<RankingsClient.RankingScores>

getRankingTopScores(String rankingId, int timeDimension, int maxResults, boolean isRealTime)

Obtains the scores on the first page on a leaderboard. The data can be obtained from the local cache.

void

submitRankingScore(String rankingId, long score, String scoreTips)

Asynchronously submits the score of the current player with a custom unit.

void

submitRankingScore(String rankingId, long score)

Asynchronously submits the score of the current player without a custom unit.

Task<ScoreSubmissionInfo>

submitScoreWithResult(String rankingId, long score, String scoreTips)

Synchronously submits the score of the current player with a custom unit.

Task<ScoreSubmissionInfo>

submitScoreWithResult(String rankingId, long score)

Synchronously submits the score of the current player without a custom unit.

Task<Integer>

getRankingSwitchStatus()

Obtains the current player's leaderboard switch setting.

Task<Integer>

setRankingSwitchStatus(int status)

Sets the leaderboard switch for the current player.

Public Methods

public Task<Intent> getTotalRankingsIntent()

Obtains the Intent object of the leaderboard list screen.

Return Values

Type

Description

Task<Intent>

Intent object of the leaderboard list screen. You can call the startActivityForResult method to switch to the screen.

Notice:
Only devices with HUAWEI AppAssistant 10.3.0 or later installed support this function.


You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<Intent> getRankingIntent(String rankingId, int timeDimension)

Obtains the Intent object of the screen for a specified leaderboard in a specified time frame.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

timeDimension

Time frame.

  • 0: The daily leaderboard is obtained.

  • 1: The weekly leaderboard is obtained.

  • 2: The all-time leaderboard is obtained.

Return Values

Type

Description

Task<Intent>

Intent object of a leaderboard. You can call the startActivityForResult method to switch to the screen.

Notice:
Only devices with HUAWEI AppAssistant 10.3.0 or later installed support this function.


You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<Intent> getRankingIntent(String rankingId)

Obtains the Intent object of the screen for a specified leaderboard in all time frames.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

Return Values

Type

Description

Task<Intent>

Intent object of a leaderboard. You can call the startActivityForResult method to switch to the screen.

Notice:
Only devices with HUAWEI AppAssistant 10.3.0 or later installed support this function.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<RankingScore> getCurrentPlayerRankingScore(String rankingId, int timeDimension)

Obtains the score of a player on a specified leaderboard in a specified time frame.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

timeDimension

Time frame.

  • 0: The daily leaderboard is obtained.

  • 1: The weekly leaderboard is obtained.

  • 2: The all-time leaderboard is obtained.

Return Values

Type

Description

Task<RankingScore>

Score of a player on a leaderboard, which is obtained from the RankingScore object that is returned.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<List<Ranking>> getRankingSummary(boolean isRealTime)

Obtains all leaderboard data. You can specify whether to obtain the data from Huawei game server or the local cache.

Input Parameters

Parameter Name

Parameter Description

isRealTime

Indicates whether to obtain leaderboard data from Huawei game server.

  • true: Obtain data from Huawei game server.

  • false: Obtain data from the local cache.

Return Values

Type

Description

Task<List<Ranking>>

All leaderboard data. 

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<Ranking> getRankingSummary(String rankingId, boolean isRealTime)

Obtains the data of a specified leaderboard. You can specify whether to obtain the data from Huawei game server or the local cache.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

isRealTime

Indicates whether to obtain leaderboard data from Huawei game server.

  • true: Obtain data from Huawei game server.

  • false: Obtain data from the local cache.

Return Values

Type

Description

Task<Ranking>

Data of a specified leaderboard.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<RankingsClient.RankingScores> getMoreRankingScores(String rankingId,long offsetPlayerRank, int maxResults, int pageDirection, int timeDimension)

Obtains scores on a leaderboard in pagination mode.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

offsetPlayerRank

Rank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded.

For example, if offsetPlayerRank is set to 5 and pageDirection is set to 0, one additional page of scores starting from the fifth rank downwards will be loaded.

maxResults

Maximum number of records on each page. The value is an integer ranging from 1 to 21.

pageDirection

Data obtaining direction.

  • 0: next page

  • 1: previous page

timeDimension

Time frame in which a leaderboard is to be obtained.

  • 0: The daily leaderboard s obtained.

  • 1: The weekly leaderboard is obtained.

  • 2: The all-time leaderboard is obtained.

Return Values

Type

Description

Task<RankingsClient.RankingScores>

List of scores on a specified leaderboard.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<RankingsClient.RankingScores> getPlayerCenteredRankingScores(String rankingId, int timeDimension, int maxResults, boolean isRealTime)

Obtains scores of a leaderboard with the current player's score displayed in the center. The data can be obtained from the local cache. For example, if a player ranks fifth on a leaderboard, this method can be used to obtain the scores of a specified number of players before and after the current player.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

timeDimension

Time frame.

  • 0: daily

  • 1: weekly

  • 2: all-time

maxResults

Maximum number of records on each page. The value is an integer ranging from 1 to 21.

isRealTime

Indicates whether to obtain leaderboard data from Huawei game server.

  • true: Obtain data from Huawei game server.

  • false: Obtain data from the local cache.

Return Values

Type

Description

Task<RankingsClient.RankingScores>

List of scores on a specified leaderboard where the current player's score is displayed in the center.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<RankingsClient.RankingScores> getPlayerCenteredRankingScores(String rankingId, int timeDimension,int maxResults, long offsetPlayerRank, int pageDirection)

Obtains scores of a leaderboard with the current player's score displayed in the center. The data can be obtained only from Huawei game server.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

timeDimension

Time frame.

  • 0: daily

  • 1: weekly

  • 2: all-time

maxResults

Maximum number of records on each page. The value is an integer ranging from 1 to 21.

offsetPlayerRank

Rank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded.

For example, if offsetPlayerRank is set to 5 and pageDirection is set to 0, one additional page of scores starting from the fifth rank downwards will be loaded.

This parameter does not take effect when this API is called for the first time. By default, the starting position is the current player's rank.

pageDirection

Data obtaining direction.

  • 0: next page

  • 1: previous page

Return Values

Type

Description

Task<RankingsClient.RankingScores>

Information about a specified score.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<RankingsClient.RankingScores> getRankingTopScores(String rankingId, int timeDimension, int maxResults, long offsetPlayerRank, int pageDirection)

Obtains scores on the first page of a leaderboard. The data can be obtained only from Huawei game server.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

timeDimension

Time frame.

  • 0: daily

  • 1: weekly

  • 2: all-time

maxResults

Maximum number of records on each page. The value is an integer ranging from 1 to 21.

offsetPlayerRank

Rank specified by offsetPlayerRank. Then one page of scores before or after (specified by pageDirection) a rank will be loaded.

For example, if offsetPlayerRank is set to 5 and pageDirection is set to 0, one additional page of scores starting from the fifth rank downwards will be loaded.

pageDirection

Data obtaining direction. Currently, only the value 0 is supported, indicating that data of the next page is obtained.

Return Values

Type

Description

Task<RankingsClient.RankingScores>

Information about a specified score.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<RankingsClient.RankingScores> getRankingTopScores(String rankingId, int timeDimension, int maxResults, boolean isRealTime)

Obtains scores on the first page of a leaderboard. The data can be obtained only from the local cache.

Input Parameters

Parameter Name

Parameter Description

rankingId

ID of a leaderboard for which data is to be obtained.

timeDimension

Time frame.

  • 0: daily

  • 1: weekly

  • 2: all-time

maxResults

Maximum number of records on each page. The value is an integer ranging from 1 to 200.

isRealTime

Indicates whether to obtain leaderboard data from Huawei game server.

  • true: Obtain data from Huawei game server.

  • false: Obtain data from the local cache.

Return Values

Type

Description

Task<RankingsClient.RankingScores>

Information about a specified score.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public void submitRankingScore(String rankingId, long score, String scoreTips)

Asynchronously submits the score of the current player with a custom unit.

This method is submitted asynchronously. To be specific, if the device is not connected to the network when the app client calls this method, the HMS SDK caches the data locally. The data is submitted to the Huawei server when network connection is restored and the user logs in again. It is unnecessary for developers to pay attention to the execution result of this method.

Input Parameters

Parameter Name

Parameter Description

rankingId

Leaderboard ID.

score

Score of the current player.

scoreTips

Score tag. Only letters, digits, underscores (_), and hyphens (-) are supported.

public void submitRankingScore(String rankingId, long score)

Asynchronously submits the score of the current player without a custom unit.

This method is submitted asynchronously. To be specific, if the device is not connected to the network when the app client calls this method, the HMS SDK caches the data locally. The data is submitted to the Huawei server when network connection is restored and the user logs in again. It is unnecessary for developers to pay attention to the execution result of this method.

Input Parameters

Parameter Name

Parameter Description

rankingId

Leaderboard ID.

score

Score of the current player.

public Task<ScoreSubmissionInfo> submitScoreWithResult(String rankingId, long score, String scoreTips)

Synchronously submits the score of the current player with a custom unit.

This method submits requests synchronously. That is, requests are immediately sent to Huawei game server after an app client calls this method, and the execution result is returned immediately.

Input Parameters

Parameter Name

Parameter Description

rankingId

Leaderboard ID.

score

Score of the current player.

scoreTips

Score tag. Only letters, digits, underscores (_), and hyphens (-) are supported.

Return Values

Type

Description

Task<ScoreSubmissionInfo>

Submission result.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<ScoreSubmissionInfo> submitScoreWithResult(String rankingId, long score)

Synchronously submits the score of the current player without a custom unit.

This method submits requests synchronously. That is, requests are immediately sent to Huawei game server after an app client calls this method, and the execution result is returned immediately.

Input Parameters

Parameter Name

Parameter Description

rankingId

Leaderboard ID.

score

Score of the current player.

Return Values

Type

Description

Task<ScoreSubmissionInfo>

Submission result.

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<Integer> getRankingSwitchStatus()

Obtains the leaderboard switch setting. Indicates whether a player agrees to report their scores to leaderboards. The switch is disabled by default upon first sign-in of the player.

Return Values

Type

Description

Task<Integer>

Indicates whether to return the leaderboard switch setting in asynchronous mode.

  • 0: no

  • 1: yes

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.

public Task<Integer> setRankingSwitchStatus(int status)

Sets the leaderboard switch.

Input Parameters

Parameter Name

Parameter Description

status

Status of the leaderboard switch to be set.

  • 0: off

  • 1: on

Return Values

Type

Description

Task<Integer>

Indicates whether to return the leaderboard switch setting in asynchronous mode.

  • 0: no

  • 1: yes

You need to set two callback listeners in the Task returned by the API. OnSuccessListener obtains the data returned in the success scenario, and OnFailureListener obtains the information about the request failure. In OnFailureListener, you need to check whether the exception object called back in this mode is an ApiException instance object, and resolve the failure according to getStatusCode() contained in the ApiException instance.