The recommended API for starting and managing a Cast Remote Display session. It simplifies
the creation of a local foreground service to render a CastPresentation
.
Your MyCastRemoteDisplayLocalService should extend CastRemoteDisplayLocalService
and
should be declared in the manifest as follows:
<service android:name=".MyCastRemoteDisplayLocalService" android:exported="false" />
This class should be inherited to create the CastPresentation
on the onCreatePresentation(Display)
call. This guarantees that the
Presentation
lifecycle is associated with the Service. There will be a
Notification
associated with the service
To create the service call startService(Context, Class extends CastRemoteDisplayLocalService>, String, CastDevice, CastRemoteDisplayLocalService.NotificationSettings, CastRemoteDisplayLocalService.Callbacks)
and to terminate
the service call stopService()
.
Application developers can provide their own Notification
.
Nested Class Summary
interface | CastRemoteDisplayLocalService.Callbacks | Callbacks for the Cast Remote Display session initiated using
CastRemoteDisplayLocalService . |
|
class | CastRemoteDisplayLocalService.NotificationSettings | Notification settings. | |
class | CastRemoteDisplayLocalService.Options | Options for a remote display session. |
Inherited Constant Summary
Public Constructor Summary
Public Method Summary
static CastRemoteDisplayLocalService |
getInstance()
The singleton instance of the
CastRemoteDisplayLocalService . |
IBinder | |
void |
onCreate()
|
abstract void |
onCreatePresentation(Display display)
The API that will be called when the Cast Remote Display has been created.
|
abstract void |
onDismissPresentation()
The API that will be called when the Cast Remote Display should be dismissed because the
Cast Remote Display session is ending.
|
int |
onStartCommand(Intent intent, int flags, int startId)
|
static void |
startService(Context activityContext, Class<? extends CastRemoteDisplayLocalService> serviceClass, String applicationId, CastDevice device, CastRemoteDisplayLocalService.NotificationSettings notificationSettings, CastRemoteDisplayLocalService.Callbacks callbacks)
Starts the
CastRemoteDisplayLocalService instance and initiates the remote display
session. |
static void |
startServiceWithOptions(Context activityContext, Class<? extends CastRemoteDisplayLocalService> serviceClass, String applicationId, CastDevice device, CastRemoteDisplayLocalService.Options options, CastRemoteDisplayLocalService.NotificationSettings notificationSettings, CastRemoteDisplayLocalService.Callbacks callbacks)
Starts the
CastRemoteDisplayLocalService instance and initiates the remote display
session. |
static void |
stopService()
Stops the
CastRemoteDisplayLocalService instance and terminates the remote display
session. |
void |
updateNotificationSettings(CastRemoteDisplayLocalService.NotificationSettings notificationSettings)
Modifies the current notification settings.
|
Protected Method Summary
Display | |
static void |
setDebugEnabled()
Enables debug logs.
|
Inherited Method Summary
Public Constructors
public CastRemoteDisplayLocalService ()
Public Methods
public static CastRemoteDisplayLocalService getInstance ()
The singleton instance of the CastRemoteDisplayLocalService
.
Returns
- The
CastRemoteDisplayLocalService
instance.
public void onCreate ()
public abstract void onCreatePresentation (Display display)
The API that will be called when the Cast Remote Display has been created. The implementation
of the service that extends CastRemoteDisplayLocalService
must implement this API to
create a CastPresentation
instance.
Parameters
display | The Cast Remote Display. |
---|
public abstract void onDismissPresentation ()
The API that will be called when the Cast Remote Display should be dismissed because the
Cast Remote Display session is ending. The implementation of the service that extends
CastRemoteDisplayLocalService
must implement this API to dismiss the
CastPresentation
instance.
public static void startService (Context activityContext, Class<? extends CastRemoteDisplayLocalService> serviceClass, String applicationId, CastDevice device, CastRemoteDisplayLocalService.NotificationSettings notificationSettings, CastRemoteDisplayLocalService.Callbacks callbacks)
Starts the CastRemoteDisplayLocalService
instance and initiates the remote display
session. If a session is already being started it will be ignored.
Parameters
activityContext | The context of the activity that is starting the service.
The cast presentation will create its own Context based
on this Context and information from the Cast Remote Display.
Must not be null . |
---|---|
serviceClass | The class of the service that should be started. The service should be
declared in the manifest (see CastRemoteDisplayLocalService ).
Must not be null . |
applicationId | The Remote Display application ID provided in the Cast developer portal.
Must not be null . |
device | The device that will host the Cast Remote Display session.
Must not be null . |
notificationSettings | The notificationSettings. It must at least contain a custom
Notification or a notification PendingIntent . Must not be null . |
callbacks | The Cast Remote Display session listener. Must not be null .
|
public static void startServiceWithOptions (Context activityContext, Class<? extends CastRemoteDisplayLocalService> serviceClass, String applicationId, CastDevice device, CastRemoteDisplayLocalService.Options options, CastRemoteDisplayLocalService.NotificationSettings notificationSettings, CastRemoteDisplayLocalService.Callbacks callbacks)
Starts the CastRemoteDisplayLocalService
instance and initiates the remote display
session. If a session is already being started it will be ignored.
Parameters
activityContext | The context of the activity that is starting the service.
The cast presentation will create its own Context based
on this Context and information from the Cast Remote Display.
Must not be null . |
---|---|
serviceClass | The class of the service that should be started. The service should be
declared in the manifest (see CastRemoteDisplayLocalService ).
Must not be null . |
applicationId | The Remote Display application ID provided in the Cast developer portal.
Must not be null . |
device | The device that will host the Cast Remote Display session.
Must not be null . |
options | Options for the session.
Must not be null . |
notificationSettings | The notificationSettings. It must at least contain a custom
Notification or a notification PendingIntent . Must not be null . |
callbacks | The Cast Remote Display session listener. Must not be null .
|
public static void stopService ()
Stops the CastRemoteDisplayLocalService
instance and terminates the remote display
session.
public void updateNotificationSettings (CastRemoteDisplayLocalService.NotificationSettings notificationSettings)
Modifies the current notification settings. Settings should be consistent with the type of
notification model used (default or custom).
For example you can replace the existing custom notification, or you can set a new
PendingIntent
, title or text for the default notification.
Parameters
notificationSettings | The new notification settings. |
---|
Protected Methods
protected Display getDisplay ()
Returns
- The
Display
object available for the remote display session, otherwisenull
(if the Cast Remote Display session has not started).
protected static void setDebugEnabled ()
Enables debug logs. This method is meant for development purposes only.