BondManager

class BondManager(context: Context)

Manages Bluetooth device bonding (pairing) operations.

Bonding is the process of establishing a trusted relationship between two Bluetooth devices. Once bonded, devices can automatically reconnect and communicate securely without requiring user interaction for each connection.

This class provides a reactive approach to bonding using Kotlin coroutines Flow, allowing callers to observe bond state changes in real-time.

Bond States

Usage Example

val bondManager = BondManager(context)

bondManager.bondDevice(bluetoothDevice)
.collect { bondState ->
when (bondState) {
BondState.BOND_BONDING -> showPairingDialog()
BondState.BOND_BONDED -> onPairingSuccessful()
BondState.BOND_NONE -> onPairingFailed()
}
}

Permissions

Requires android.Manifest.permission.BLUETOOTH_CONNECT on Android 12 (API 31) and above.

Parameters

context

The Android Context used to register broadcast receivers for bond state changes.

See also

Constructors

Link copied to clipboard
constructor(context: Context)

Functions

Link copied to clipboard

Initiates bonding with the specified Bluetooth device and returns a Flow of bond state updates.