The PlayersClient class defines methods related to player information.
| Return | Method |
| Task<Player> | getCurrentPlayer() Obtains the Player object of the currently signed-in player. |
| Task<String> | 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) |
Obtains the Player object of the currently signed-in player.
Return Values
| Type | Description |
| 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
- Task<Player> task = client.getCurrentPlayer();
- task.addOnSuccessListener(new OnSuccessListener<Player>() {
- @Override
- public void onSuccess(Player player) {
- String playerId = player.getPlayerId();
- }
- }).addOnFailureListener(new OnFailureListener() {
- @Override
- public void onFailure(Exception e) {
- if (e instanceof ApiException) {
- (ApiException) e).getStatusCode()
- }
- }
- });
Obtains the locally cached player ID of the current player.
Return Values
The ID of a player is returned.
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 |
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.
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.
|
eventType | Type of an event.
|
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.
Stores the information about a player in a game, such as the level and region.
Input Parameters
Parameter Name | Parameter Description |
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.