Skip to content

Instantly share code, notes, and snippets.

@tdcolvin
Created January 8, 2024 20:54
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/c2003c6d6d7aae007a3e4867ac47212c to your computer and use it in GitHub Desktop.
Save tdcolvin/c2003c6d6d7aae007a3e4867ac47212c to your computer and use it in GitHub Desktop.
private val callback = object: BluetoothGattCallback() {
...
override fun onCharacteristicChanged(
gatt: BluetoothGatt?,
characteristic: BluetoothGattCharacteristic
) {
super.onCharacteristicChanged(gatt, characteristic)
Log.v("bluetooth", characteristic.value.contentToString())
}
}
@RequiresPermission(PERMISSION_BLUETOOTH_CONNECT)
fun startReceivingPasswordUpdates() {
val service = gatt?.getService(CTF_SERVICE_UUID)
val characteristic = service?.getCharacteristic(PASSWORD_CHARACTERISTIC_UUID)
if (characteristic != null) {
gatt?.setCharacteristicNotification(characteristic, true)
val CLIENT_CONFIG_DESCRIPTOR = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")
val desc = characteristic.getDescriptor(CLIENT_CONFIG_DESCRIPTOR)
desc?.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE)
gatt?.writeDescriptor(desc)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment