onCharacteristicChanged

open override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, value: ByteArray)

Called when a characteristic value has changed due to a notification or indication (API 33+).

This modern callback is invoked on Android 13 (API 33) and later. The characteristic value is passed directly as a parameter, which is safer than reading from the characteristic object and avoids potential race conditions.

Parameters

gatt

The BluetoothGatt instance for the connection.

characteristic

The BluetoothGattCharacteristic whose value has changed.

value

The new value of the characteristic as a ByteArray.

See also

ConnectionStateMachine.handleCharacteristicChanged

open override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic)

Deprecated

Deprecated in API 33. Use onCharacteristicChanged(BluetoothGatt, BluetoothGattCharacteristic, ByteArray) instead.

Replace with

onCharacteristicChanged(gatt, characteristic, value)

Called when a characteristic value has changed due to a notification or indication (API < 33).

This legacy callback is invoked on Android versions prior to API 33 (Android 13). The characteristic value must be retrieved from the characteristic object itself.

Note: This method is deprecated in favor of the API 33+ variant that passes the value directly as a parameter, avoiding potential race conditions.

Parameters

gatt

The BluetoothGatt instance for the connection.

characteristic

The BluetoothGattCharacteristic whose value has changed. Call BluetoothGattCharacteristic.getValue to retrieve the new value.

See also

ConnectionStateMachine.handleCharacteristicChanged