ProjectedDeviceController


@ExperimentalProjectedApi
public final class ProjectedDeviceController implements AutoCloseable


Controller for the Projected device.

Use create to create an instance of this class. Call close when finished with this instance to release resources.

Summary

Nested types

Represents an intrinsic piece of functionality of a Projected device, i.e., what it is capable of.

Public methods

final void
addBatteryStateChangedListener(
    @NonNull CoroutineContext context,
    @NonNull Function1<@NonNull BatteryStateUnit> listener
)

Adds a listener for battery state changes.

void

Releases resources, unregistering any active listeners.

static final @NonNull ProjectedDeviceController
@RequiresApi(value = 34)
create(@NonNull Context context)

Connects to the service providing features for Projected devices and returns the ProjectedDeviceController when the connection is established.

final @NonNull List<@NonNull AudioDeviceInfo>

Returns the list of AudioDeviceInfo objects associated with the projected device.

final @NonNull Set<@NonNull ProjectedDeviceController.Capability>

The capabilities of the Projected device.

final void

Removes a previously added listener.

Public methods

addBatteryStateChangedListener

Added in 1.0.0-alpha09
public final void addBatteryStateChangedListener(
    @NonNull CoroutineContext context,
    @NonNull Function1<@NonNull BatteryStateUnit> listener
)

Adds a listener for battery state changes.

The listener lambda will be executed in a new coroutine launched within the provided context. The listener will be automatically unregistered when the context's Job is canceled.

close

Added in 1.0.0-alpha09
public void close()

Releases resources, unregistering any active listeners. This instance should not be used after calling close.

create

@RequiresApi(value = 34)
public static final @NonNull ProjectedDeviceController create(@NonNull Context context)

Connects to the service providing features for Projected devices and returns the ProjectedDeviceController when the connection is established. The caller is responsible for calling close on the returned instance when it's no longer needed to release all internal resources.

Parameters
@NonNull Context context

The context to use for binding to the service.

Throws
IllegalStateException

if the projected service is not found or binding is not permitted

getAudioDevices

Added in 1.0.0-alpha09
public final @NonNull List<@NonNull AudioDeviceInfogetAudioDevices()

Returns the list of AudioDeviceInfo objects associated with the projected device.

getCapabilities

Added in 1.0.0-alpha09
public final @NonNull Set<@NonNull ProjectedDeviceController.CapabilitygetCapabilities()

The capabilities of the Projected device.

These capabilities represent intrinsic functionality of the device that will not change over the lifetime of the device, for example, whether the device is capable of showing a visual user interface at all, regardless of whether the screen is currently on or off.

removeBatteryStateChangedListener

Added in 1.0.0-alpha09
public final void removeBatteryStateChangedListener(
    @NonNull Function1<@NonNull BatteryStateUnit> listener
)

Removes a previously added listener. Note: Listeners are also automatically removed when their associated CoroutineScope is canceled.