enableNotifications

fun enableNotifications(serviceUuid: UUID, characteristicUuid: UUID, onNotification: (ByteArray) -> Unit, onComplete: (Int) -> Unit)

Enables notifications for a GATT characteristic.

This method performs the following steps:

  1. Enables local notification listening via BluetoothGatt.setCharacteristicNotification.

  2. Writes the BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE to the Client Characteristic Configuration Descriptor (CCCD) to enable server-side notifications.

Once enabled, the onNotification callback will be invoked each time the device sends a notification with the updated characteristic value.

The state machine must be in ConnectionState.Ready for this operation to succeed. The characteristic must support notifications (have a CCCD descriptor).

Parameters

serviceUuid

The UUID of the GATT service containing the characteristic.

characteristicUuid

The UUID of the characteristic to enable notifications for.

onNotification

Callback invoked with the new value each time a notification is received. This callback may be called multiple times until notifications are disabled.

onComplete

Invoked once when the notification setup completes. BluetoothGatt.GATT_SUCCESS indicates notifications are now active.

See also

Throws

if Bluetooth permissions are not granted.