Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Created January 5, 2024 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdcolvin/75fd3612008291aa9d7d6d06079b7b8c to your computer and use it in GitHub Desktop.
Save tdcolvin/75fd3612008291aa9d7d6d06079b7b8c to your computer and use it in GitHub Desktop.
private val callback = object: BluetoothGattCallback() {
...
@Deprecated("Deprecated in Java")
override fun onCharacteristicRead(
gatt: BluetoothGatt,
characteristic: BluetoothGattCharacteristic,
status: Int
) {
super.onCharacteristicRead(gatt, characteristic, status)
if (characteristic.uuid == myCharacteristicUUID) {
Log.v("bluetooth", String(characteristic.value))
}
}
}
@RequiresPermission(PERMISSION_BLUETOOTH_CONNECT)
fun readCharacteristic(serviceUUID: UUID, characteristicUUID: UUID) {
val service = gatt?.getService(serviceUUID)
val characteristic = service?.getCharacteristic(characteristicUUID)
if (characteristic != null) {
val success = gatt?.readCharacteristic(characteristic)
Log.v("bluetooth", "Read status: $success")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment