Android 4.3中的'onCharacteristicChanged'回调但是在Android 5.0中没有调用。 'WriteCharacteristic'和'setCharaceristicNotification'成功,'onCharacteristicWrite'回调成功。为什么不在Android5.0或Android 6.0中调用。
这是我的通知代码:
private void notification(BluetoothGattCharacteristic gattCharacteristic, String tag) {
boolean success = mBluetoothGatt.setCharacteristicNotification(gattCharacteristic, true);
if (success) {
for (BluetoothGattDescriptor dp : gattCharacteristic.getDescriptors()) {
if (dp != null) {
if ((gattCharacteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_NOTIFY) != 0) {
dp.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
Log.i(TAG,"notification NOTIFICATION value = "+ Arrays.toString(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE));
} else if ((gattCharacteristic.getProperties() & BluetoothGattCharacteristic.PROPERTY_INDICATE) != 0) {
dp.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
Log.i(TAG,"notification INDICATION value = "+ Arrays.toString(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE));
}
mBluetoothGatt.writeDescriptor(dp);
Log.i(TAG, tag + " notification successful");
}
}
}
}
答案 0 :(得分:0)
“BluetoothGatt.writeDescriptor(dp)”失败,它是一个异步线程。当线程忙时,停止写描述符。所以我逐一写出描述符。没关系。