BluetoothHelper

class BluetoothHelper(context: Context)(source)

Helper Bluetooth centralisé.

Permissions requises (API 31+) :

  • BLUETOOTH_SCAN → découverte d'appareils

  • BLUETOOTH_CONNECT → connexion / lecture du nom

API < 31 : BLUETOOTH + BLUETOOTH_ADMIN.

Enregistrement Koin :

single { BluetoothHelper(androidContext()) }

Utilisation :

// État courant
val state = bluetoothHelper.getState()

// Appareils couplés
val paired = bluetoothHelper.getPairedDevices()

// Observer l'état
bluetoothHelper.stateFlow.onEach { state -> … }.launchIn(viewModelScope)

// Scanner (Flow d'appareils découverts)
bluetoothHelper.scanFlow(BluetoothScanConfig.Quick)
.onEach { device -> … }
.launchIn(viewModelScope)

Constructors

Link copied to clipboard
constructor(context: Context)

Properties

Link copied to clipboard

Functions

Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.BLUETOOTH_CONNECT", "android.permission.BLUETOOTH"])
fun getPairedDevices(): Set<BluetoothDevice>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.BLUETOOTH_SCAN", "android.permission.BLUETOOTH_ADMIN", "android.permission.BLUETOOTH", "android.permission.ACCESS_FINE_LOCATION"])
fun scanFlow(config: BluetoothScanConfig = BluetoothScanConfig.Default): Flow<BluetoothDevice>