API reference

DeviceSelectorBase Class

Implements DeviceSelector
Modifiers: abstract
Abstract base class for DeviceSelector implementations that provides common device observation infrastructure.
This class handles the shared pattern of eagerly observing a device selection flow and caching the latest selected device for synchronous access. Subclasses only need to provide the specific device selection Flow via the deviceFlow constructor parameter.
The observation starts immediately at construction time using WearableCoroutineScopes.applicationScope with WearableDispatchers.io, ensuring that DeviceSelectorBase.activeDevice always returns the most recent value without requiring callers to collect the flow.

See Also

Constructors

DeviceSelectorBase ( deviceFlow )
Signature
constructor(deviceFlow: Flow<DeviceIdentifier?>)
Parameters
deviceFlow: Flow<DeviceIdentifier?>  The flow that emits the currently selected device identifier, or null when no device is selected. This flow is eagerly collected and its latest value is cached.

Methods

activeDevice ()
Returns the currently selected device identifier, or null if no device is selected.
This provides synchronous access to the latest selected device. The value is eagerly cached from the underlying device selection flow, so it always reflects the most recent state without requiring flow collection.
Signature
open override fun activeDevice(): DeviceIdentifier?
Returns
DeviceIdentifier?  The DeviceIdentifier of the currently selected device, or null if no suitable device is available
activeDeviceFlow ()
Returns a Flow that emits the currently selected device identifier, or null when no device is selected.
Use this to reactively observe device selection changes. The flow emits whenever the selected device changes — for example, when a device connects, disconnects, or when the selector switches to a different device.
Signature
open override fun activeDeviceFlow(): Flow<DeviceIdentifier?>
Returns
Flow<DeviceIdentifier?>  A Flow of DeviceIdentifier representing the active device, or null when no suitable device is available