近日公司有搞BLE的需求,回调接口中的onCharacteristicChanged()方法,一直没有执行,但是的的确确硬件那边是发到这边来了,但是怎么也收不掉。从市场上下的其他的BLE工具确实是收到。
进行了以下检查
1 检查用作notify的Characteristic的UUID是否正确
2 setCharacteristicNotification(chara, true) 检测已经设置
3
BluetoothGattDescriptor descriptor = chara.getDescriptor(com.hengda.smart.smartpen.bluetooth.HD_Profile.UUID_CHAR_NOTIFY_DIS);
if(descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE)){
} 已设置已经写
==============================================================================================================================================
最终解决方案
硬件这边作为notify的Characteristic有两个Descriptor应该讲其的的两个Descriptor的值都设置为ENABLE_INDICATION_VALUE
for(BluetoothGattDescriptor dp:chara.getDescriptors()){ dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); gatt.writeDescriptor(dp); }