BluetoothConnectivityService

interface BluetoothConnectivityService

Interface which can be extended by a service implementation, which is responsible for providing clients with information about nearby Bluetooth devices, and functionality to change the connection state of those devices.

The configuration mode indicates when a UI is currently visible which allows a user to make changes to the connectivity state of Bluetooth devices. The mode is intended to be enabled by multiple clients. A client can call enableConfigurationMode to enable the configuration mode and disableConfigurationMode to disable it. The isConfigurationModeEnabled flag can be observed by a client in order to show a UI related to Bluetooth configuration when it is set to true and to stop showing the UI when the flag is set to false.

Types

Link copied to clipboard
interface BluetoothPairingRequestListener

Clients can implement this listener to know when a pairing request has been received.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract val connectableProfiles: Set<BluetoothDeviceProfile>

Set of all Bluetooth profiles which are supported by the platform and are connectable. When a profile is connectable, the connection policy can be altered by using method setProfileConnectionPolicy.

Link copied to clipboard

Map of all the Bluetooth devices where the key is a unique identifier referring to a BluetoothDeviceAddress entry and where the value provides the current BluetoothDeviceInformation of the device.

Link copied to clipboard
abstract val isConfigurationModeEnabled: Boolean

Indicates if the configuration mode is currently enabled. Can be used by a client to show in a UI that configuration mode is enabled.

Link copied to clipboard
abstract val isDiscoveryActive: Boolean

Indicates when the discovery process is active.

Link copied to clipboard
abstract val recentlyConnectedDevices: List<BluetoothDeviceAddress>

List of BluetoothDeviceAddresses of the most recently connected Bluetooth devices ordered by how recently they were connected to, with the most recent first and least recent last. The list includes the current connected devices.

Functions

Link copied to clipboard
abstract suspend fun acceptPairing(deviceAddress: BluetoothDeviceAddress, pairingDetails: BluetoothPairingDetails): Boolean

Provides the currently running pairing process with the required pairingDetails, so it can be finalised successfully.

Link copied to clipboard
abstract suspend fun cleanupNeverPairedDevices()
Link copied to clipboard
abstract suspend fun connect(deviceAddress: BluetoothDeviceAddress)

Connects to a specific Bluetooth device which is registered to BluetoothDeviceAddress. BluetoothConnectivityStatus.connectionState will be updated for the device entry in deviceInformation.

Link copied to clipboard
abstract suspend fun disableConfigurationMode()

Disables configuration mode by setting the isConfigurationModeEnabled to false.

Link copied to clipboard
abstract suspend fun disconnect(deviceAddress: BluetoothDeviceAddress)

Disconnects from a specific Bluetooth device which is registered to BluetoothDeviceAddress. BluetoothConnectivityStatus.connectionState will be updated for the device entry in deviceInformation.

Link copied to clipboard
abstract suspend fun enableConfigurationMode()

Enables configuration mode by setting the isConfigurationModeEnabled to true.

Link copied to clipboard
abstract suspend fun executeDiscoveryProcessOnce()

Start discovering devices. When devices are nearby and discoverable they will be added to deviceInformation.

Link copied to clipboard
abstract suspend fun forgetPairedDevice(deviceAddress: BluetoothDeviceAddress)

Removes bond (pairing) with a specific Bluetooth device which is registered to BluetoothDeviceAddress. It deletes the link key associated with that device and, by doing so, the connections to that device are terminated immediately.

Link copied to clipboard
abstract suspend fun getProfileConnectionPolicies(    profile: BluetoothDeviceProfile,     deviceConnectionState: BluetoothConnectivityStatus.BluetoothConnectionState? = null,     deviceBondState: BluetoothConnectivityStatus.BluetoothBondState? = null): Map<BluetoothDeviceAddress, BluetoothProfileConnectionPolicy>

Retrieves the platform side connection policies of a specific Bluetooth profile for all devices in a specific connection state and/or specific bond state.

Link copied to clipboard
abstract suspend fun getProfileConnectionPolicy(deviceAddress: BluetoothDeviceAddress, profile: BluetoothDeviceProfile): BluetoothProfileConnectionPolicy

Retrieves the platform side connection policy of a specific Bluetooth profile for a specific Bluetooth device.

Link copied to clipboard
abstract suspend fun setProfileConnectionPolicy(    deviceAddress: BluetoothDeviceAddress,     profile: BluetoothDeviceProfile,     isAllowed: Boolean): Boolean

Sets the platform side connection policy for a specific Bluetooth device, which is registered to BluetoothDeviceAddress. The connection policy of the remote device is not impacted and will not change.

Link copied to clipboard
abstract suspend fun startPairing(deviceAddress: BluetoothDeviceAddress): Boolean

Initiates pairing with a specific Bluetooth device which is registered to BluetoothDeviceAddress. Once the bond state has changed BluetoothConnectivityStatus.bondState will be update for the device entry in deviceInformation.

Link copied to clipboard
abstract suspend fun stopPairing()

Stops the currently running pairing process and BluetoothConnectivityStatus.bondState will be set to BluetoothConnectivityStatus.BluetoothBondState.UNPAIRED for the device entry in deviceInformation.