public static interface

Cast.CastApi

com.google.android.gms.cast.Cast.CastApi

Class Overview

The main entry point for interacting with a Google Cast device.

Summary

Public Methods
abstract ApplicationMetadata getApplicationMetadata(GoogleApiClient client)
Returns the metadata for the currently running receiver application, if any.
abstract String getApplicationStatus(GoogleApiClient client)
Returns the current receiver application status, if any.
abstract double getVolume(GoogleApiClient client)
Returns the device's volume, in the range [0.0, 1.0].
abstract boolean isMute(GoogleApiClient client)
Returns the device's mute state.
abstract PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client)
Joins (connects to) the currently running application on the receiver.
abstract PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client, String applicationId, String sessionId)
Joins (connects to) an application on the receiver.
abstract PendingResult<Cast.ApplicationConnectionResult> joinApplication(GoogleApiClient client, String applicationId)
Joins (connects to) the currently running application on the receiver.
abstract PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId, LaunchOptions launchOptions)
Launches an application on the receiver.
abstract PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId)
Launches an application on the receiver.
abstract PendingResult<Cast.ApplicationConnectionResult> launchApplication(GoogleApiClient client, String applicationId, boolean relaunchIfRunning)
abstract PendingResult<Status> leaveApplication(GoogleApiClient client)
Leaves (disconnects from) the receiver application.
abstract void removeMessageReceivedCallbacks(GoogleApiClient client, String namespace)
Removes a Cast.MessageReceivedCallback from this controller for a given namespace.
abstract void requestStatus(GoogleApiClient client)
Requests the receiver's current status.
abstract PendingResult<Status> sendMessage(GoogleApiClient client, String namespace, String message)
Sends a message to the currently connected application.
abstract void setMessageReceivedCallbacks(GoogleApiClient client, String namespace, Cast.MessageReceivedCallback callbacks)
Sets a new Cast.MessageReceivedCallback listener on this controller for a given namespace.
abstract void setMute(GoogleApiClient client, boolean mute)
Mutes or unmutes the device's audio.
abstract void setVolume(GoogleApiClient client, double volume)
Sets the device volume.
abstract PendingResult<Status> stopApplication(GoogleApiClient client)
Stops any running receiver application(s).
abstract PendingResult<Status> stopApplication(GoogleApiClient client, String sessionId)
Stops the currently running receiver application, optionally doing so only if its session ID matches the supplied one.

Public Methods

public abstract ApplicationMetadata getApplicationMetadata (GoogleApiClient client)

Returns the metadata for the currently running receiver application, if any.

Parameters
client The API client with which to perform this request.
Returns
  • The application metadata, or null if no application is currently running on the receiver.
Throws
IllegalStateException If there is no active service connection.

public abstract String getApplicationStatus (GoogleApiClient client)

Returns the current receiver application status, if any. Message text is localized to the Google Cast device's locale.

Parameters
client The API client with which to perform this request.
Returns
  • The application status text, or null if no application is currently running on the receiver or if the receiver application has not provided any status text.
Throws
IllegalStateException If there is no active service connection.

public abstract double getVolume (GoogleApiClient client)

Returns the device's volume, in the range [0.0, 1.0].

Parameters
client The API client with which to perform this request.
Throws
IllegalStateException If there is no active service connection.

public abstract boolean isMute (GoogleApiClient client)

Returns the device's mute state.

Parameters
client The API client with which to perform this request.
Throws
IllegalStateException If there is no active service connection.

public abstract PendingResult<Cast.ApplicationConnectionResult> joinApplication (GoogleApiClient client)

Joins (connects to) the currently running application on the receiver. The previous PendingResult will be canceled with the Cast.ApplicationConnectionResult's status code being CANCELED.

Parameters
client The API client with which to perform this request.
Returns
  • A PendingResult which can be used to retrieve connection information.

public abstract PendingResult<Cast.ApplicationConnectionResult> joinApplication (GoogleApiClient client, String applicationId, String sessionId)

Joins (connects to) an application on the receiver. The previous PendingResult will be canceled with the Cast.ApplicationConnectionResult's status code being CANCELED.

Parameters
client The API client with which to perform this request.
applicationId The ID of the receiver application to connect to, or null to connect to the currently running application.
sessionId The expected session ID of the receiver application, or null to connect without checking for a matching session ID.
Returns
  • A PendingResult which can be used to retrieve connection information.

public abstract PendingResult<Cast.ApplicationConnectionResult> joinApplication (GoogleApiClient client, String applicationId)

Joins (connects to) the currently running application on the receiver. The previous PendingResult will be canceled with the Cast.ApplicationConnectionResult's status code being CANCELED.

Parameters
client The API client with which to perform this request.
applicationId The ID of the receiver application to connect to, or null to connect to the currently running application.
Returns
  • A PendingResult which can be used to retrieve connection information.

public abstract PendingResult<Cast.ApplicationConnectionResult> launchApplication (GoogleApiClient client, String applicationId, LaunchOptions launchOptions)

Launches an application on the receiver. The previous PendingResult will be canceled with the Cast.ApplicationConnectionResult's status code being CANCELED.

Parameters
client The API client with which to perform this request.
applicationId The ID of the receiver application to launch.
launchOptions The launch options for the request.
Returns
  • A PendingResult which can be used to retrieve connection information.

public abstract PendingResult<Cast.ApplicationConnectionResult> launchApplication (GoogleApiClient client, String applicationId)

Launches an application on the receiver. If the application is already running, it is joined (not relaunched). The previous PendingResult will be canceled with the Cast.ApplicationConnectionResult's status code being CANCELED.

Parameters
client The API client with which to perform this request.
applicationId The ID of the receiver application to launch.
Returns
  • A PendingResult which can be used to retrieve connection information.

public abstract PendingResult<Cast.ApplicationConnectionResult> launchApplication (GoogleApiClient client, String applicationId, boolean relaunchIfRunning)

This method is deprecated.
Use launchApplication(GoogleApiClient, String, LaunchOptions).

Launches an application on the receiver. The previous PendingResult will be canceled with the Cast.ApplicationConnectionResult's status code being CANCELED.

Parameters
client The API client with which to perform this request.
applicationId The ID of the receiver application to launch.
relaunchIfRunning If true, relaunches the application if it is already running.
Returns
  • A PendingResult which can be used to retrieve connection information.

public abstract PendingResult<Status> leaveApplication (GoogleApiClient client)

Leaves (disconnects from) the receiver application. If there is no currently active application session, this method does nothing. If this method is called while stopApplication(GoogleApiClient) is pending, then this method does nothing. The Status's status code will be INVALID_REQUEST.

Parameters
client The API client with which to perform this request.
Returns
  • A PendingResult which can be used to retrieve if the command was successful.

public abstract void removeMessageReceivedCallbacks (GoogleApiClient client, String namespace)

Removes a Cast.MessageReceivedCallback from this controller for a given namespace.

Parameters
client The API client with which to perform this request.
namespace The namespace of the Cast channel. Namespaces must begin with the prefix "urn:x-cast:".
Throws
IOException If an I/O error occurs while performing the request.
IllegalArgumentException If namespace is null or empty.

public abstract void requestStatus (GoogleApiClient client)

Requests the receiver's current status.

Throws
IllegalStateException If there is no active service connection.
IOException If an I/O error occurs while performing the request.

public abstract PendingResult<Status> sendMessage (GoogleApiClient client, String namespace, String message)

Sends a message to the currently connected application.

Parameters
client The API client with which to perform this request.
namespace The namespace for the message. Namespaces must begin with the prefix " urn:x-cast:".
message The message payload.
Returns
  • A PendingResult which can be used to see whether the message has been enqueued to be sent to a Google Cast device.

public abstract void setMessageReceivedCallbacks (GoogleApiClient client, String namespace, Cast.MessageReceivedCallback callbacks)

Sets a new Cast.MessageReceivedCallback listener on this controller for a given namespace. The new listener will replace an existing listener for a given namespace. Messages received by the controller for the given namespace will be forwarded to this listener. The caller must have already called connect() and received onConnected(Bundle) callback.

Parameters
client The API client with which to perform this request.
namespace The namespace of the Cast channel. Namespaces must begin with the prefix "urn:x-cast:".
callbacks The Cast.MessageReceivedCallback to perform callbacks on. May not be null.
Throws
IOException If an I/O error occurs while performing the request.
IllegalStateException Thrown when the controller is not connected to a CastDevice.
IllegalArgumentException If namespace is null or empty, or if the namespace doesn't start with the prefix "urn:x-cast:".

public abstract void setMute (GoogleApiClient client, boolean mute)

Mutes or unmutes the device's audio.

Parameters
client The API client with which to perform this request.
mute Whether to mute or unmute the audio.
Throws
IllegalStateException If there is no active service connection.
IOException If an I/O error occurs while performing the request.

public abstract void setVolume (GoogleApiClient client, double volume)

Sets the device volume. If volume is outside of the range [0.0, 1.0], then the value will be clipped.

Parameters
client The API client with which to perform this request.
volume The new volume, in the range [0.0, 1.0].
Throws
IllegalStateException If there is no active service connection.
IllegalArgumentException If the volume is infinity or NaN.
IOException If an I/O error occurs while performing the request.

public abstract PendingResult<Status> stopApplication (GoogleApiClient client)

Stops any running receiver application(s). If this method is called while leaveApplication(GoogleApiClient) is pending, then this method does nothing. The Status's status code will be INVALID_REQUEST.

Parameters
client The API client with which to perform this request.
Returns
  • A PendingResult which can be used to retrieve if the command was successful.

public abstract PendingResult<Status> stopApplication (GoogleApiClient client, String sessionId)

Stops the currently running receiver application, optionally doing so only if its session ID matches the supplied one. If this method is called while leaveApplication(GoogleApiClient) is pending, then this method does nothing. The Status's status code will be INVALID_REQUEST.

Parameters
client The API client with which to perform this request.
sessionId The session ID of the application to stop. sessionId cannot be null or an empty string.
Returns
  • A PendingResult which can be used to retrieve if the command was successful.