【发布时间】:2018-02-08 16:06:17
【问题描述】:
我想更改通知,所以我这样做了:
BluetoothGattCharacteristic init_gatt=mConnectedGatt.getService(SERVICE_UUID).getCharacteristic(CHAR_2_UUID);
mConnectedGatt.setCharacteristicNotification(init_gatt,true);
BluetoothGattDescriptor descriptor = init_gatt.getDescriptor(
UUID.fromString("00002902-0000-1000-8000-00805F9B34FB"));
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
boolean success=mConnectedGatt.writeDescriptor(descriptor);
init_gatt.setValue(new byte[]{0x19});
mConnectedGatt.writeCharacteristic(init_gatt);
所以成功是真的,但永远不会调用 onCharacteristicChanged()。 min 的一个同事在一个馅饼上完成了 在这里,我得到了一个 gatttool 写入请求的示例。
gatttool -b <MAC Address> --char-write-req --handle=0x0031 --value=0100 --listen android
其中参数为char-write-req 0x16 01:00
那么有没有办法在android中做同样的事情?
【问题讨论】:
-
您显示的代码注册了通知的特征,并且由于您在
write上收到了成功,因此您现在可以接收通知了。onCharacteristicChanged将在收到有关该特征的通知时被调用,但您连接的设备会根据自己的条件发送该通知。 -
如果您也可以写入特征(它具有该属性),那么您也应该在
writeCharacteristic调用中收到真或假结果。
标签: android notifications bluetooth-lowenergy descriptor