Last active
January 5, 2024 09:59
-
-
Save tdcolvin/a1e789960e57f79fe7f9d3ad77da55a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val callback = object: BluetoothGattCallback() { | |
... | |
override fun onCharacteristicWrite( | |
gatt: BluetoothGatt, | |
characteristic: BluetoothGattCharacteristic, | |
status: Int | |
) { | |
super.onCharacteristicWrite(gatt, characteristic, status) | |
if (characteristic.uuid == /* the one you're looking for */) { | |
Log.v("bluetooth", "Write status: $status") | |
} | |
} | |
} | |
@RequiresPermission(PERMISSION_BLUETOOTH_CONNECT) | |
fun writeCharacteristic(serviceUUID: UUID, characteristicUUID: UUID) { | |
val service = gatt?.getService(serviceUUID) | |
val characteristic = service?.getCharacteristic(characteristicUUID) | |
if (characteristic != null) { | |
// First write the new value to our local copy of the characteristic | |
characteristic.value = "Tom".toByteArray() | |
//...Then send the updated characteristic to the device | |
val success = gatt?.writeCharacteristic(characteristic) | |
Log.v("bluetooth", "Write status: $success") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment