【发布时间】:2018-03-13 19:37:11
【问题描述】:
我有一个程序可以向 ble 发送一个单词并获取一些数据。在 android 6 和 7 中运行良好。但在 android 4.4 和 5 中,oncharacteristicchanged 在 writeCharacteristic 之后没有被调用。我在启用通知和 writeCharacteristic 之间添加了一个延迟,但没有奏效。 启用通知代码:
mBluetoothGatt.setCharacteristicNotification(TxChar,true);
BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
mBluetoothGatt.writeDescriptor(descriptor);
uuid 是:
CCCD = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
RX_SERVICE_UUID = UUID.fromString("00001234-0000-1000-8000-00805f9b34fb");
RX_CHAR_UUID = UUID.fromString("00001235-0000-1000-8000-00805f9b34fb");
TX_CHAR_UUID = UUID.fromString("00001236-0000-1000-8000-00805f9b34fb");
这是日志猫
03-14 11:29:10.024 11767-12038/com.example.metasense D/BluetoothGatt: onGetCharacteristic() - Device=E3:84:5F:81:55:87 UUID=00001236-0000-1000-8000-00805f9b34fb
03-14 11:29:10.029 11767-11779/com.example.metasense D/BluetoothGatt: onGetDescriptor() - Device=E3:84:5F:81:55:87 UUID=00002902-0000-1000-8000-00805f9b34fb
03-14 11:29:10.029 11767-11778/com.example.metasense D/BluetoothGatt: onSearchComplete() = Device=E3:84:5F:81:55:87 Status=0
03-14 11:29:10.029 11767-11778/com.example.metasense D/onServicesDiscovered bt: onServicesDiscovered
03-14 11:29:10.029 11767-11778/com.example.metasense D/BluetoothService: mBluetoothGatt = android.bluetooth.BluetoothGatt@42c448d8
03-14 11:29:10.029 11767-11778/com.example.metasense D/enableTXNotification bt: enableTXNotification
03-14 11:29:10.029 11767-11778/com.example.metasense D/BluetoothGatt: setCharacteristicNotification() - uuid: 00001236-0000-1000-8000-00805f9b34fb enable: true
03-14 11:29:10.029 11767-11778/com.example.metasense D/BluetoothGatt: writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb
03-14 11:29:10.334 11767-11778/com.example.metasense D/writeRXChar bt: writeRXCharacteristic
03-14 11:29:10.334 11767-12258/com.example.metasense D/BluetoothService: mBluetoothGatt null (1/1) android.bluetooth.BluetoothGatt@42c448d8
03-14 11:29:10.334 11767-12258/com.example.metasense D/BluetoothGatt: writeCharacteristic() - uuid: 00001235-0000-1000-8000-00805f9b34fb
03-14 11:29:10.334 11767-12258/com.example.metasense D/BluetoothService: All1packs sent.
03-14 11:29:10.394 11767-12258/com.example.metasense D/akhare write bt: inja
03-14 11:29:10.404 11767-12038/com.example.metasense D/BluetoothGatt: onDescriptorWrite() - Device=E3:84:5F:81:55:87 UUID=00001236-0000-1000-8000-00805f9b34fb
03-14 11:29:13.454 11767-11794/com.example.metasense V/FA: Inactivity, disconnecting from the service
蓝牙模块是 nRF51822。请帮帮我...
【问题讨论】:
-
您需要添加更多详细信息。我们不知道为什么您的外围设备没有发送预期的数据。你有没有调试过任何东西。比如检查外设日志、嗅探器跟踪、hci 日志或 logcat?
-
谢谢。我添加了 logcat
标签: android bluetooth-lowenergy