AI-generated Key Takeaways
-
The
Cast.CastApiinterface is deprecated. -
This interface serves as the main entry point for interacting with Google Cast devices.
-
It provides methods to get information about the Cast device and running applications, as well as methods to manage applications and send messages.
-
Migration to Cast SDK v3 is recommended.
This interface is deprecated.
See Migrate Android Sender
App from Cast SDK v2 to v3.
The main entry point for interacting with a Google Cast device.
Public Method Summary
| abstract int | |
| 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 int | |
| abstract double | |
| abstract boolean | |
| 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)
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> |
launchApplication(GoogleApiClient
client, String
applicationId, boolean relaunchIfRunning)
This method is deprecated. Use
launchApplication(GoogleApiClient, String, LaunchOptions).
|
| abstract PendingResult<Cast.ApplicationConnectionResult> |
launchApplication(GoogleApiClient
client, String
applicationId)
Launches an application on the receiver.
|
| abstract PendingResult<Cast.ApplicationConnectionResult> |
launchApplication(GoogleApiClient
client, String
applicationId, LaunchOptions
launchOptions)
Launches an application on the receiver.
|
| abstract PendingResult<Status> | |
| abstract void |
removeMessageReceivedCallbacks(GoogleApiClient
client, String namespace)
Removes a
Cast.MessageReceivedCallback from this controller for a given
namespace.
|
| abstract void | |
| 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,
MessageReceivedCallback callbacks)
Sets a new
Cast.MessageReceivedCallback listener on this controller for a given
namespace.
|
| abstract void | |
| abstract void | |
| 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.
|
| abstract PendingResult<Status> |
Public Methods
public abstract int getActiveInputState (GoogleApiClient client)
Returns the device's active-input state.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|
Throws
| IllegalStateException | If there is no active service connection. |
|---|
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. Must not be
null. |
|---|
Returns
- The application metadata, or
nullif 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. Must not be
null. |
|---|
Returns
- The application status text, or
nullif 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 int getStandbyState (GoogleApiClient client)
Returns the device's standby state. The returned value is Cast.STANDBY_STATE_UNKNOWN,
Cast.STANDBY_STATE_NO,
or Cast.STANDBY_STATE_YES.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|
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. Must not be
null. |
|---|
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. Must not be
null. |
|---|
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 CastStatusCodes.CANCELED.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|
Returns
- A
PendingResultwhich 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 CastStatusCodes.CANCELED.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|---|
| applicationId | The ID of the receiver application to connect to, or null to
connect to the currently running application. |
Returns
- A
PendingResultwhich 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 CastStatusCodes.CANCELED.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|---|
| 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
PendingResultwhich 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 CastStatusCodes.CANCELED.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|---|
| applicationId | The ID of the receiver application to launch. |
| relaunchIfRunning | If true, relaunches the application if it is already running. |
Returns
- A
PendingResultwhich 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 CastStatusCodes.CANCELED.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|---|
| applicationId | The ID of the receiver application to launch. |
Returns
- A
PendingResultwhich 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 CastStatusCodes.CANCELED.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|---|
| applicationId | The ID of the receiver application to launch. |
| launchOptions | The launch options for the request. |
Returns
- A
PendingResultwhich 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 CastStatusCodes.INVALID_REQUEST.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|
Returns
- A
PendingResultwhich 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. Must not be
null. |
|---|---|
| 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. Must not be
null. |
|---|---|
| namespace | The namespace for the message. Namespaces must begin with the prefix "
urn:x-cast:". |
| message | The message payload. |
Returns
- A
PendingResultwhich 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, 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 GoogleApiClient.connect()
and received GoogleApiClient.ConnectionCallbacks#onConnected callback.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|---|
| 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. Must not be
null. |
|---|---|
| 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. Must not be
null. |
|---|---|
| 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, 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 CastStatusCodes.INVALID_REQUEST.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|---|
| sessionId | The session ID of the application to stop. sessionId cannot be
null or an empty string. |
Returns
- A
PendingResultwhich can be used to retrieve if the command was successful.
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 CastStatusCodes.INVALID_REQUEST.
Parameters
| client | The API client with which to perform this request. Must not be
null. |
|---|
Returns
- A
PendingResultwhich can be used to retrieve if the command was successful.