CastRemoteDisplayLocalService

public abstract classCastRemoteDisplayLocalServiceextendsService

This class is deprecated.
The Remote Display feature is deprecated and will be removed in a future release.

The recommended API for starting and managing a Cast Remote Display session. It simplifies the creation of a local foreground service to render aCastPresentation.

The foreground service allows the lifecycle of the Activity display to be decoupled from from the lifecycle of the CastPresentation, minimizing complexity on the application code. This will allow an app to continue rendering onto the Remote Display while, for example, the activity is in background. The service runs on the main thread of the application.

Your MyCastRemoteDisplayLocalService should extend CastRemoteDisplayLocalServiceand should be declared in the manifest as follows:

<service android:name= ".MyCastRemoteDisplayLocalService" android:exported= "false" />

This class should be inherited to create theCastPresentation on the onCreatePresentation(Display)call. This guarantees that thePresentation lifecycle is associated with the Service. There will be aNotification 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 ownNotification.

Nested Class Summary

interface CastRemoteDisplayLocalService.Callbacks Callbacks for the Cast Remote Display session initiated usingCastRemoteDisplayLocalService.
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
onBind(Intent intent)
void
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<? extendsCastRemoteDisplayLocalService> serviceClass,String applicationId,CastDevice device, CastRemoteDisplayLocalService.NotificationSettingsnotificationSettings, CastRemoteDisplayLocalService.Callbackscallbacks)
Starts the CastRemoteDisplayLocalServiceinstance and initiates the Remote Display session.
static void
startServiceWithOptions(Context activityContext,Class<? extendsCastRemoteDisplayLocalService> serviceClass,String applicationId,CastDevice device, CastRemoteDisplayLocalService.Optionsoptions, CastRemoteDisplayLocalService.NotificationSettingsnotificationSettings, CastRemoteDisplayLocalService.Callbackscallbacks)
Starts the CastRemoteDisplayLocalServiceinstance and initiates the Remote Display session.
static void
stopService()
Stops the CastRemoteDisplayLocalServiceinstance and terminates the Remote Display session.
void
updateNotificationSettings(CastRemoteDisplayLocalService.NotificationSettings notificationSettings)
This method is deprecated. The Remote Display feature is deprecated. Calling this method will do nothing for devices running Android S or above. You need to build your own notification settings for those devices.

Protected Method Summary

Display
getCastRemoteDisplay()
Returns theDisplay object available for the Remote Display session, otherwisenull (if the Cast Remote Display session has not started).
static void
setDebugEnabled()
Enables debug logs.

Inherited Method Summary

Public Constructors

publicCastRemoteDisplayLocalService()

Public Methods

public staticCastRemoteDisplayLocalService getInstance()

The singleton instance of theCastRemoteDisplayLocalService.

Returns

publicIBinderonBind(Intent intent)

public voidonCreate()

public abstract voidonCreatePresentation(Display display)

The API that will be called when the Cast Remote Display has been created. The implementation of the service that extendsCastRemoteDisplayLocalService must implement this API to create aCastPresentation instance.

Parameters
display The Cast Remote Display.

public abstract voidonDismissPresentation()

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 extendsCastRemoteDisplayLocalService must implement this API to dismiss theCastPresentation instance.

public intonStartCommand(Intentintent, int flags, int startId)

public static voidstartService(Context activityContext,Class<? extendsCastRemoteDisplayLocalService> serviceClass,String applicationId,CastDevicedevice, CastRemoteDisplayLocalService.NotificationSettingsnotificationSettings, CastRemoteDisplayLocalService.Callbackscallbacks)

Starts theCastRemoteDisplayLocalService 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 ownContext based on thisContext and information from the Cast Remote Display. Must not benull.
serviceClass The class of the service that should be started. The service should be declared in the manifest (see CastRemoteDisplayLocalService). Must not benull.
applicationId The Remote Display application ID provided in the Cast developer portal. Must not benull.
device The device that will host the Cast Remote Display session. Must not be null.
notificationSettings The notificationSettings. It must at least contain a customNotification or a notificationPendingIntent. Must not benull.
callbacks The Cast Remote Display session listener. Must not benull.

public static voidstartServiceWithOptions(Context activityContext,Class<? extendsCastRemoteDisplayLocalService> serviceClass,String applicationId,CastDevicedevice, CastRemoteDisplayLocalService.Optionsoptions, CastRemoteDisplayLocalService.NotificationSettingsnotificationSettings, CastRemoteDisplayLocalService.Callbackscallbacks)

Starts theCastRemoteDisplayLocalService 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 ownContext based on thisContext and information from the Cast Remote Display. Must not benull.
serviceClass The class of the service that should be started. The service should be declared in the manifest (see CastRemoteDisplayLocalService). Must not benull.
applicationId The Remote Display application ID provided in the Cast developer portal. Must not benull.
device The device that will host the Cast Remote Display session. Must not be null.
options Options for the session. Must not benull.
notificationSettings The notificationSettings. It must at least contain a customNotification or a notificationPendingIntent. Must not benull.
callbacks The Cast Remote Display session listener. Must not benull.

public static voidstopService()

Stops theCastRemoteDisplayLocalService instance and terminates the Remote Display session.

public voidupdateNotificationSettings(CastRemoteDisplayLocalService.NotificationSettings notificationSettings)

This method is deprecated.
The Remote Display feature is deprecated. Calling this method will do nothing for devices running Android S or above. You need to build your own notification settings for those devices.

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 newPendingIntent, title or text for the default notification.

Parameters
notificationSettings The new notification settings.

Protected Methods

protectedDisplay getCastRemoteDisplay()

Returns theDisplayobject available for the Remote Display session, otherwisenull(if the Cast Remote Display session has not started).

protected static voidsetDebugEnabled()

Enables debug logs. This method is meant for development purposes only.