public abstract class RemoteDisplayProvider extends Object
To implement your remote display provider service, create a subclass of
Service
and override the Service.onBind()
method
to return the provider's binder when the SERVICE_INTERFACE
is requested.
public class SampleRemoteDisplayProviderService extends Service { private SampleProvider mProvider; public IBinder onBind(Intent intent) { if (intent.getAction().equals(RemoteDisplayProvider.SERVICE_INTERFACE)) { if (mProvider == null) { mProvider = new SampleProvider(this); } return mProvider.getBinder(); } return null; } class SampleProvider extends RemoteDisplayProvider { public SampleProvider() { super(SampleRemoteDisplayProviderService.this); } // --- Implementation goes here --- } }
Declare your remote display provider service in your application manifest like this:
<application> <uses-library android:name="com.android.media.remotedisplay" /> <service android:name=".SampleRemoteDisplayProviderService" android:label="@string/sample_remote_display_provider_service" android:exported="true" android:permission="android.permission.BIND_REMOTE_DISPLAY"> <intent-filter> <action android:name="com.android.media.remotedisplay.RemoteDisplayProvider" /> </intent-filter> </service> </application>
This object is not thread safe. It is only intended to be accessed on the
main looper thread
of an application.
IMPORTANT: This class is effectively a public API for unbundled applications, and must remain API stable. See README.txt in the root of this package for more information.
Modifier and Type | Field and Description |
---|---|
static int |
DISCOVERY_MODE_ACTIVE
Discovery mode: Active discovery.
|
static int |
DISCOVERY_MODE_NONE
Discovery mode: Do not perform any discovery.
|
static int |
DISCOVERY_MODE_PASSIVE
Discovery mode: Passive or low-power periodic discovery.
|
static String |
SERVICE_INTERFACE
The
Intent that must be declared as handled by the service. |
Constructor and Description |
---|
RemoteDisplayProvider(Context context)
Creates a remote display provider.
|
Modifier and Type | Method and Description |
---|---|
void |
addDisplay(RemoteDisplay display)
Adds the specified remote display and notifies the system.
|
RemoteDisplay |
findRemoteDisplay(String id)
Finds the remote display with the specified id, returns null if not found.
|
IBinder |
getBinder()
Gets the Binder associated with the provider.
|
Context |
getContext()
Gets the context of the remote display provider.
|
int |
getDiscoveryMode()
Gets the current discovery mode.
|
Collection<RemoteDisplay> |
getDisplays()
Gets the current collection of displays.
|
PendingIntent |
getSettingsPendingIntent()
Gets a pending intent to launch the remote display settings activity.
|
void |
onAdjustVolume(RemoteDisplay display,
int delta)
Called when the system would like to adjust the volume of a display.
|
void |
onConnect(RemoteDisplay display)
Called when the system would like to connect to a display.
|
void |
onDisconnect(RemoteDisplay display)
Called when the system would like to disconnect from a display.
|
void |
onDiscoveryModeChanged(int mode)
Called when the current discovery mode changes.
|
void |
onSetVolume(RemoteDisplay display,
int volume)
Called when the system would like to set the volume of a display.
|
void |
removeDisplay(RemoteDisplay display)
Removes the specified remote display and tells the system about it.
|
void |
updateDisplay(RemoteDisplay display)
Updates information about the specified remote display and notifies the system.
|
public static final String SERVICE_INTERFACE
Intent
that must be declared as handled by the service.
Put this in your manifest.public static final int DISCOVERY_MODE_NONE
public static final int DISCOVERY_MODE_PASSIVE
This mode indicates that an application is interested in knowing whether there are any remote displays paired or available but doesn't need the latest or most detailed information. The provider may scan at a lower rate or rely on knowledge of previously paired devices.
public static final int DISCOVERY_MODE_ACTIVE
This mode indicates that the user is actively trying to connect to a route and we should perform continuous scans. This mode may use significantly more power but is intended to be short-lived.
public RemoteDisplayProvider(Context context)
context
- The application context for the remote display provider.public final Context getContext()
public IBinder getBinder()
This is intended to be used for the onBind() method of a service that implements a remote display provider service.
public void onDiscoveryModeChanged(int mode)
mode
- The new discovery mode.public void onConnect(RemoteDisplay display)
display
- The remote display.public void onDisconnect(RemoteDisplay display)
display
- The remote display.public void onSetVolume(RemoteDisplay display, int volume)
display
- The remote display.volume
- The desired volume.public void onAdjustVolume(RemoteDisplay display, int delta)
display
- The remote display.delta
- An increment to add to the current volume, such as +1 or -1.public int getDiscoveryMode()
public Collection<RemoteDisplay> getDisplays()
public void addDisplay(RemoteDisplay display)
display
- The remote display that was added.IllegalStateException
- if there is already a display with the same id.public void updateDisplay(RemoteDisplay display)
display
- The remote display that was added.IllegalStateException
- if the display was npublic void removeDisplay(RemoteDisplay display)
display
- The remote display that was removed.public RemoteDisplay findRemoteDisplay(String id)
id
- Id of the remote display.public PendingIntent getSettingsPendingIntent()