public final class

GameManagerClient

extends Object
java.lang.Object
   ↳ com.google.android.gms.cast.games.GameManagerClient

Class Overview

Provides access to the GameManager APIs. This class allows to send requests to a connected Google Cast receiver device and get updates when game state changes. This class is thread safe.

Summary

Nested Classes
interface GameManagerClient.GameManagerInstanceResult Result of a game manager client creation command. 
interface GameManagerClient.GameManagerResult Result of a game manager command. 
interface GameManagerClient.Listener A listener that can be set in GameManagerClient to be notified when game manager state is updated or when game messages are received for players controlled by this sender. 
Constants
int GAMEPLAY_STATE_LOADING Gameplay indicating that the game is loading.
int GAMEPLAY_STATE_PAUSED Gameplay state indicating that the game is paused.
int GAMEPLAY_STATE_RUNNING Gameplay state indicating that the game is running.
int GAMEPLAY_STATE_SHOWING_INFO_SCREEN Gameplay state indicating that the game is showing an information screen.
int GAMEPLAY_STATE_UNKNOWN Unknown gameplay state.
int LOBBY_STATE_CLOSED Lobby state indicating that the lobby is closed and not accepting players.
int LOBBY_STATE_OPEN Lobby state indicating that the lobby is open and accepting players to join.
int LOBBY_STATE_UNKNOWN Unknown lobby state.
int PLAYER_STATE_AVAILABLE Player state indicating that the player is connected to the receiver and available to join a game.
int PLAYER_STATE_DROPPED Player state indicating that the player is no longer connected to the receiver because of a network drop.
int PLAYER_STATE_IDLE Player state indicating that the player is connected to the receiver, in the game , and idle.
int PLAYER_STATE_PLAYING Player state indicating that the player is connected to the receiver, in the game , and actively playing.
int PLAYER_STATE_QUIT Player state indicating that the player has purposefully chosen to disconnect from the receiver.
int PLAYER_STATE_READY Player state indicating that the player is connected to the receiver, and ready to enter the game.
int PLAYER_STATE_UNKNOWN Unknown player state.
int STATUS_INCORRECT_VERSION Status code indicating the version of the game manager in this client library does not match the version of the game manager running on the cast receiver.
int STATUS_TOO_MANY_PLAYERS Status code indicating the number of players connected and available on the receiver is greater than the maximum number of players specified in the configuration of the receiver game.
Public Methods
void dispose()
Releases all resources associated with this object.
GameManagerState getCurrentState()
Returns the current state of the game manager.
static PendingResult<GameManagerClient.GameManagerInstanceResult> getInstanceFor(GoogleApiClient googleApiClient, String castSessionId)
Constructs a new GameManagerClient using the provided GoogleApiClient.
String getLastUsedPlayerId()
Returns the id of the last controllable player on which a player request was performed and completed successfully.
boolean isDisposed()
Returns whether dispose() has been called.
void sendGameMessage(String playerId, JSONObject extraMessageData)
Sends a game specific message to the receiver, its contents are entirely up to the application.
void sendGameMessage(JSONObject extraMessageData)
Sends a game specific message to the receiver, its contents are entirely up to the application.
PendingResult<GameManagerClient.GameManagerResult> sendGameRequest(JSONObject extraMessageData)
Sends a game specific message to the receiver, its contents are entirely up to the application.
PendingResult<GameManagerClient.GameManagerResult> sendGameRequest(String playerId, JSONObject extraMessageData)
Sends a game specific message to the receiver, its contents are entirely up to the application.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerAvailableRequest(String playerId, JSONObject extraMessageData)
Sends a request to the receiver to transition a player into PLAYER_STATE_AVAILABLE.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerAvailableRequest(JSONObject extraMessageData)
Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_AVAILABLE.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerIdleRequest(JSONObject extraMessageData)
Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_IDLE.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerIdleRequest(String playerId, JSONObject extraMessageData)
Sends a request to the receiver to transition a player into PLAYER_STATE_IDLE.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerPlayingRequest(JSONObject extraMessageData)
Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_PLAYING.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerPlayingRequest(String playerId, JSONObject extraMessageData)
Sends a request to the receiver to transition a player into PLAYER_STATE_PLAYING.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerQuitRequest(JSONObject extraMessageData)
Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_QUIT.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerQuitRequest(String playerId, JSONObject extraMessageData)
Sends a request to the receiver to transition a player into PLAYER_STATE_QUIT.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerReadyRequest(String playerId, JSONObject extraMessageData)
Sends a request to the receiver to transition a player into PLAYER_STATE_READY.
PendingResult<GameManagerClient.GameManagerResult> sendPlayerReadyRequest(JSONObject extraMessageData)
Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_READY.
void setListener(GameManagerClient.Listener listener)
Set the game manager client listener, which will trigger callbacks when the game receives updates from the receiver device.
void setSessionLabel(String sessionLabel)
Sets the session label, which will be used as the prefix for log messages.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int GAMEPLAY_STATE_LOADING

Gameplay indicating that the game is loading.

Constant Value: 1 (0x00000001)

public static final int GAMEPLAY_STATE_PAUSED

Gameplay state indicating that the game is paused.

Constant Value: 3 (0x00000003)

public static final int GAMEPLAY_STATE_RUNNING

Gameplay state indicating that the game is running.

Constant Value: 2 (0x00000002)

public static final int GAMEPLAY_STATE_SHOWING_INFO_SCREEN

Gameplay state indicating that the game is showing an information screen.

Constant Value: 4 (0x00000004)

public static final int GAMEPLAY_STATE_UNKNOWN

Unknown gameplay state.

Constant Value: 0 (0x00000000)

public static final int LOBBY_STATE_CLOSED

Lobby state indicating that the lobby is closed and not accepting players.

Constant Value: 2 (0x00000002)

public static final int LOBBY_STATE_OPEN

Lobby state indicating that the lobby is open and accepting players to join.

Constant Value: 1 (0x00000001)

public static final int LOBBY_STATE_UNKNOWN

Unknown lobby state.

Constant Value: 0 (0x00000000)

public static final int PLAYER_STATE_AVAILABLE

Player state indicating that the player is connected to the receiver and available to join a game.

Constant Value: 3 (0x00000003)

public static final int PLAYER_STATE_DROPPED

Player state indicating that the player is no longer connected to the receiver because of a network drop.

Constant Value: 1 (0x00000001)

public static final int PLAYER_STATE_IDLE

Player state indicating that the player is connected to the receiver, in the game , and idle.

Constant Value: 5 (0x00000005)

public static final int PLAYER_STATE_PLAYING

Player state indicating that the player is connected to the receiver, in the game , and actively playing.

Constant Value: 6 (0x00000006)

public static final int PLAYER_STATE_QUIT

Player state indicating that the player has purposefully chosen to disconnect from the receiver.

Constant Value: 2 (0x00000002)

public static final int PLAYER_STATE_READY

Player state indicating that the player is connected to the receiver, and ready to enter the game.

Constant Value: 4 (0x00000004)

public static final int PLAYER_STATE_UNKNOWN

Unknown player state.

Constant Value: 0 (0x00000000)

public static final int STATUS_INCORRECT_VERSION

Status code indicating the version of the game manager in this client library does not match the version of the game manager running on the cast receiver.

Constant Value: 2150 (0x00000866)

public static final int STATUS_TOO_MANY_PLAYERS

Status code indicating the number of players connected and available on the receiver is greater than the maximum number of players specified in the configuration of the receiver game.

Constant Value: 2151 (0x00000867)

Public Methods

public void dispose ()

Releases all resources associated with this object. It will no longer get updates for state changes on the receiver device. After calling this method, further interactions with this object, except for dispose() and isDisposed() will raise an IllegalStateException.

public GameManagerState getCurrentState ()

Returns the current state of the game manager.

Returns
GameManagerState
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public static PendingResult<GameManagerClient.GameManagerInstanceResult> getInstanceFor (GoogleApiClient googleApiClient, String castSessionId)

Constructs a new GameManagerClient using the provided GoogleApiClient. This is an async operation.

Parameters
googleApiClient GoogleApiClient: The API client with which to perform the operation. Must be connected and contain the correct APIs.
castSessionId String: The session ID of the cast application session running on the receiver.
Returns
PendingResult<GameManagerClient.GameManagerInstanceResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalArgumentException if passed googleApiClient is null, not connected or it doesn't contain the Cast API, or if castSessionId is null or empty.

public String getLastUsedPlayerId ()

Returns the id of the last controllable player on which a player request was performed and completed successfully. This can be null if no response from the receiver has been received as the result of a player request.

Returns
String
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public boolean isDisposed ()

Returns whether dispose() has been called.

Returns
boolean

public void sendGameMessage (String playerId, JSONObject extraMessageData)

Sends a game specific message to the receiver, its contents are entirely up to the application. The message will originate from the last used local player. This is a fire-and-forget method. To track the progress of the message, use sendGameRequest(String, JSONObject).

Parameters
playerId String: The id of the controllable player sending this message.
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public void sendGameMessage (JSONObject extraMessageData)

Sends a game specific message to the receiver, its contents are entirely up to the application. The message will originate from the last used local player. This is a fire-and-forget method. To track the progress of the message, use sendGameRequest(String, JSONObject).

Parameters
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendGameRequest (JSONObject extraMessageData)

Sends a game specific message to the receiver, its contents are entirely up to the application. The message will originate from the last used controllable player. The receiver will send a response back to this sender.

Parameters
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendGameRequest (String playerId, JSONObject extraMessageData)

Sends a game specific message to the receiver, its contents are entirely up to the application. The receiver will send a response back to this sender.

Parameters
playerId String: The id of the controllable player sending this message.
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerAvailableRequest (String playerId, JSONObject extraMessageData)

Sends a request to the receiver to transition a player into PLAYER_STATE_AVAILABLE. If the player's transition is invalid, the GameManagerClient.GameManagerResult will contain an error. If the playerId is null, a new player will be registered and its player ID will be set as the last used player id when the receiver responds to this request.

Parameters
playerId String: The id of the controllable player to be affected by this state change.
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerAvailableRequest (JSONObject extraMessageData)

Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_AVAILABLE. If this is not a valid transition for that player an error will be returned in the result object. If the last used player is unknown, a new player will be registered and its player ID will be set as the last used player when the receiver responds to this request.

Parameters
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerIdleRequest (JSONObject extraMessageData)

Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_IDLE. If the player's transition is invalid, or if the last used player is unknown, the GameManagerClient.GameManagerResult will contain an error.

Parameters
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerIdleRequest (String playerId, JSONObject extraMessageData)

Sends a request to the receiver to transition a player into PLAYER_STATE_IDLE. If the player's transition is invalid, the GameManagerClient.GameManagerResult will contain an error.

Parameters
playerId String: The id of the controllable player to be affected by this state change.
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerPlayingRequest (JSONObject extraMessageData)

Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_PLAYING. If the player's transition is invalid, or if the last used player is unknown, the GameManagerClient.GameManagerResult will contain an error.

Parameters
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerPlayingRequest (String playerId, JSONObject extraMessageData)

Sends a request to the receiver to transition a player into PLAYER_STATE_PLAYING. If the player's transition is invalid, the GameManagerClient.GameManagerResult will contain an error.

Parameters
playerId String: The id of the controllable player to be affected by this state change.
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerQuitRequest (JSONObject extraMessageData)

Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_QUIT. If the last used player is unknown, the GameManagerClient.GameManagerResult will contain an error.

Parameters
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerQuitRequest (String playerId, JSONObject extraMessageData)

Sends a request to the receiver to transition a player into PLAYER_STATE_QUIT.

Parameters
playerId String: The id of the controllable player to be affected by this state change.
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerReadyRequest (String playerId, JSONObject extraMessageData)

Sends a request to the receiver to transition a player into PLAYER_STATE_READY. If the player's transition is invalid, the GameManagerClient.GameManagerResult will contain an error.

Parameters
playerId String: The id of the controllable player to be affected by this state change.
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public PendingResult<GameManagerClient.GameManagerResult> sendPlayerReadyRequest (JSONObject extraMessageData)

Sends a request to the receiver to transition the last used player by this sender into PLAYER_STATE_READY. If the player's transition is invalid, or if the last used player is unknown, the GameManagerClient.GameManagerResult will contain an error.

Parameters
extraMessageData JSONObject: Custom application-specific data to pass along with the request.
Returns
PendingResult<GameManagerClient.GameManagerResult> A PendingResult which can be used to track the progress of the request.
Throws
IllegalStateException If there is no connection with the receiver device or if the Game Manager Client has been disposed.

public void setListener (GameManagerClient.Listener listener)

Set the game manager client listener, which will trigger callbacks when the game receives updates from the receiver device.

Parameters
listener GameManagerClient.Listener

public void setSessionLabel (String sessionLabel)

Sets the session label, which will be used as the prefix for log messages.

Parameters
sessionLabel String: The prefix for logging messages. If null or an empty string is passed no operation will be performed.