Quicknav Quicknav
Links

- Google Play Developer Console
- Android Developers Blog
- About Android

Android Sites

- Android.com
- Android Developers
- Android Open Source Project

close

- - Get Started
  - Style
  - Patterns
  - Building Blocks
  - Downloads
  - Videos
- - Training
  - API Guides
  - Reference
  - Tools
    - Get the SDK
  - Google Services
- - Google Play
  - Publishing
  - Promoting
  - App Quality
  - Spotlight
  - Open Distribution

## Results

Loading...
Summary: Nested Classes | Constants | Fields | Inherited Methods | [Expand All]
public final class

# Cast

extends Object

java.lang.Object
↳ | com.google.android.gms.cast.Cast

## Class Overview

Main entry point for the Cast APIs. This class provides APIs and interfaces to access Google Cast devices.

To use the service, construct a `GoogleApiClient.Builder` and pass `API` to `addApi(Api)`. Once you have your `GoogleApiClient`, call `connect()` and wait for the `onConnected(Bundle)` method to be called.

Device discovery on Android is performed using the Android MediaRouter APIs that debuted in Jellybean MR2 (API level 18). The MediaRouter APIs are implemented in the Android v7 Support Library. These APIs provide a simple mechanism for discovering media destinations, such as Chromecasts, bluetooth speakers, Android-powered smart TVs, and other media playback devices; and for routing media content to and controlling playback on those endpoints. These endpoints are referred to as “media routes.”

1. The first step to using these APIs is to acquire the MediaRouter singleton. It is important for the application to hold on to the reference to this singleton for as long as the application will be using the MediaRouter APIs; otherwise it may get garbage collected at an inopportune time.
2. Next, an appropriate route selector must be constructed. The purpose of the route selector is to filter the routes down to only those that the application is interested in such as Cast devices. It is also possible to filter the routes further by supported receiver application, in the (typical) case where the sender application expects to use a specific one.
3. Third, a MediaRouter callback is constructed. This callback has methods that will be called by the MediaRouter whenever a route becomes available or unavailable or a route is selected by the user.

## Summary

Nested Classes
interface | Cast.ApplicationConnectionResult | When a connection to a receiver application has been established, this object contains information about that application, including its `ApplicationMetadata` and current status.
interface | Cast.CastApi | The main entry point for interacting with a Cast device.
class | Cast.CastOptions | API configuration parameters for `Cast`.
class | Cast.Listener | The interface for `Cast` callbacks.
interface | Cast.MessageReceivedCallback | The interface to process received messages from a `CastDevice`.

Constants
String | EXTRA_APP_NO_LONGER_RUNNING | A boolean extra for the connection hint bundle passed to `onConnected(Bundle)` that indicates that the connection was re-established, but the receiver application that was in use at the time of the connection loss is no longer running on the receiver.
int | MAX_MESSAGE_LENGTH | The maximum raw message length (in bytes) that is supported by a Cast channel.
int | MAX_NAMESPACE_LENGTH | The maximum length (in characters) of a namespace name.

Fields
public static final Api | API | Token to pass to `addApi(Api)` to enable the Cast features.
public static final Cast.CastApi | CastApi | An implementation of the CastApi interface.

[Expand] Inherited Methods

From class java.lang.Object

Object | clone()
boolean | equals(Object arg0)
void | finalize()
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)

## Constants

#### public static final String EXTRA_APP_NO_LONGER_RUNNING

A boolean extra for the connection hint bundle passed to `onConnected(Bundle)` that indicates that the connection was re-established, but the receiver application that was in use at the time of the connection loss is no longer running on the receiver.

Constant Value: "com.google.android.gms.cast.EXTRA_APP_NO_LONGER_RUNNING"

#### public static final int MAX_MESSAGE_LENGTH

The maximum raw message length (in bytes) that is supported by a Cast channel.

Constant Value: 65536 (0x00010000)

#### public static final int MAX_NAMESPACE_LENGTH

The maximum length (in characters) of a namespace name.

Constant Value: 128 (0x00000080)

## Fields

#### public static final Api API

Token to pass to `addApi(Api)` to enable the Cast features.

#### public static final Cast.CastApi CastApi

An implementation of the CastApi interface. The interface is used to interact with a cast device.