getCharacteristicValue

fun getCharacteristicValue(characteristicUUID: UUID): ByteArray?

Gets the current stored value of a characteristic.

Returns the value that was last set via setCharacteristicValue, sendNotification, or written by a connected central device. This is the same value that would be returned to a central performing a read operation.

Example: Reading Back a Stored Value

val batteryLevelUUID = UUID.fromString("00002A19-0000-1000-8000-00805f9b34fb")

// Check current stored battery level
val currentLevel = gattServer.getCharacteristicValue(batteryLevelUUID)
if (currentLevel != null) {
val percentage = currentLevel[0].toInt() and 0xFF
Log.d(TAG, "Current battery level: $percentage%")
} else {
Log.d(TAG, "Battery level not yet set")
}

Return

The current value as a ByteArray, or null if no value has been set for this characteristic

Parameters

characteristicUUID

The UUID of the characteristic to query

See also