目录

The PlayersClient class defines methods related to player information.

Public Method Summary

ReturnMethod
Task<Player>getCurrentPlayer()
Obtains the Player object of the currently signed-in player.
Task<String>

getCachePlayerId()

Obtains the locally cached player ID of the current player.
Task<PlayerExtraInfo>

getPlayerExtraInfo(String transactionId)

Obtains the additional information about a player.
Task<String>

submitPlayerEvent(String playerId,String eventId,String eventType)

Reports player behavior events.
Task<void>

savePlayerInfo(AppPlayerInfo appPlayerInfo)

Public Methods

public Task<Player> getCurrentPlayer()

Obtains the Player object of the currently signed-in player.

Return Values

TypeDescription
Task<Player>Player object of the Player type.

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.

Example

  1. Task<Player> task = client.getCurrentPlayer();
  2. task.addOnSuccessListener(new OnSuccessListener<Player>() {
  3.   @Override
  4.    public void onSuccess(Player player) {
  5.        String playerId = player.getPlayerId();
  6.    }
  7.    }).addOnFailureListener(new OnFailureListener() {
  8.    @Override
  9.    public void onFailure(Exception e) {
  10.        if  (e instanceof ApiException) {
  11.            (ApiException) e).getStatusCode()
  12.        }
  13.    }
  14. });

public Task<String> getCachePlayerId()

Obtains the locally cached player ID of the current player.

Return Values

The ID of a player is returned.

public Task<PlayerExtraInfo> getPlayerExtraInfo(String transactionId)

Obtains the additional information about a player.

Input Parameters

Parameter Name

Parameter Description

transactionId

Transaction ID returned by Huawei game server after an app calls the submitPlayerEvent method to report a player event of entering a game.

If a transaction ID exists, the ID is   passed. If a transaction ID does not exist, null is passed.

Return Values

Type

Description

PlayerExtraInfo

Additional player information returned asynchronously.

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<String> submitPlayerEvent(String playerId,String eventId,String eventType)

Reports an event when a player enters or exits a game.

Input Parameters

Parameter Name

Parameter Description

playerId

ID of the current player.

eventId

Player event ID.

  • When eventType is GAMEBEGIN,  pass a random number as the value of eventId. The number must be unique under the app, and can contain a maximum of 64   characters.

  • When eventType is GAMEEND,   pass the transactionId returned after submitPlayerEvent is called when a player enters a game as the value of eventId.

eventType

Type of an event.

  • GAMEBEGIN: Enters a game.

  • GAMEEND: Exits a game.

Return Values

Type

Description

String

Transaction ID allocated by Huawei game   server to a player in the scenario where eventType is set to GAMEBEGIN. In other   scenarios, null 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<void> savePlayerInfo(AppPlayerInfo appPlayerInfo)

Stores the information about a player in a game, such as the level and region.

Input Parameters

Parameter Name

Parameter Description

AppPlayerInfo

Details about a player in a game.

Return Values

None.

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.