Bond Manager
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
BondState.BOND_NONE - No bond exists; devices are not paired
BondState.BOND_BONDING - Bonding is in progress; user may need to confirm pairing
BondState.BOND_BONDED - Devices are successfully bonded/paired
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
The Android Context used to register broadcast receivers for bond state changes.