java.lang.Object | |
↳ | com.google.android.gms.cast.framework.CastContext |
A singleton class containing global context for the Cast SDK. The shared instance can be accessed
by calling getSharedInstance(Context)
.
To properly initialize CastContext
, the application must have a class that implements
OptionsProvider
interface:
package com.example.app; public class CastOptionsProvider implements OptionsProvider { @Override public CastOptions getCastOptions(Context appContext) { ... } }and specify its fully qualified class name in the AndroidManifest.xml with the key
OPTIONS_PROVIDER_CLASS_NAME_KEY
:
... <meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME" android:value="com.example.app.CastOptionsProvider" /> ...All public methods must be called from the main thread.
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
String | OPTIONS_PROVIDER_CLASS_NAME_KEY | The metadata key to specify the fully qualified name of the OptionsProvider
implementation in the AndroidManifest.xml. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds an
AppVisibilityListener to listen for UI visibility events. | |||||||||||
Adds a
CastStateListener to monitor changes of the current CastState . | |||||||||||
Returns the
CastOptions . | |||||||||||
Returns the current
CastState . | |||||||||||
Returns the merged
MediaRouteSelector used for discovering devices and deciding
whether to show the MediaRouteButton. | |||||||||||
Returns the
SessionManager , never returns null . | |||||||||||
Returns a shared instance of
CastContext . | |||||||||||
Returns
true if the application is visible. | |||||||||||
If your application supports SDK versions before JELLY BEAN, you should call this method to
delegate the handling of physical volume key events to the SDK so that users can use the
physical volume keys to control device volume of the Cast receiver.
| |||||||||||
This method is deprecated.
The minimum Android SDK version supported by the Cast SDK is now
ICE_CREAM_SANDWICH , so this method is no longer
necessary. This method is now a no-op.
| |||||||||||
Removes an
AppVisibilityListener . | |||||||||||
Removes a
CastStateListener . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
The metadata key to specify the fully qualified name of the OptionsProvider
implementation in the AndroidManifest.xml.
Adds an AppVisibilityListener
to listen for UI visibility events.
Parameters | |
---|---|
listener |
AppVisibilityListener
|
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
NullPointerException |
If listener is null .
|
Adds a CastStateListener
to monitor changes of the current CastState
.
Parameters | |
---|---|
listener |
CastStateListener
|
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
NullPointerException |
If listener is null .
|
Returns the CastOptions
.
Returns | |
---|---|
CastOptions |
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
Returns the current CastState
.
Returns | |
---|---|
int |
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
Returns the merged MediaRouteSelector
used for discovering devices and deciding
whether to show the MediaRouteButton. This selector is merged with any additional
SessionProvider
s that might be registered with the CastContext.
Returns | |
---|---|
MediaRouteSelector |
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
Returns the SessionManager
, never returns null
.
Returns | |
---|---|
SessionManager |
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
Returns a shared instance of CastContext
. The shared instance will be initialized
on the first time this method is called.
Parameters | |
---|---|
context |
Context :
An application Context . If this is not an application Context ,
getApplicationContext() will be called on the given context, to retrieve it. |
Returns | |
---|---|
CastContext |
Throws | |
---|---|
IllegalStateException |
If
|
Returns true
if the application is visible.
Returns | |
---|---|
boolean |
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
If your application supports SDK versions before JELLY BEAN, you should call this method to
delegate the handling of physical volume key events to the SDK so that users can use the
physical volume keys to control device volume of the Cast receiver. Clients should override
dispatchKeyEvent(KeyEvent)
and call this method:
@Override public boolean dispatchKeyEvent(KeyEvent event) { return CastContext.getSharedInstance().onDispatchVolumeKeyEventBeforeJellyBean(event) || super.dispatchKeyEvent(event); }The amount of volume delta to increase or decrease is set through
setVolumeDeltaBeforeIceCreamSandwich(double)
.
This method is a no-op on platform JELLY BEAN and above.
Parameters | |
---|---|
event |
KeyEvent :
The dispatched event.
|
Returns | |
---|---|
boolean |
This method is deprecated.
The minimum Android SDK version supported by the Cast SDK is now
ICE_CREAM_SANDWICH
, so this method is no longer
necessary. This method is now a no-op.
Parameters | |
---|---|
activity |
FragmentActivity
|
savedInstanceState |
Bundle
|
Removes an AppVisibilityListener
.
Parameters | |
---|---|
listener |
AppVisibilityListener
|
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |
Removes a CastStateListener
.
Parameters | |
---|---|
listener |
CastStateListener
|
Throws | |
---|---|
IllegalStateException |
If this method is not called on the main thread. |