无法从智能蓝牙设备Android获取数据

无法从智能蓝牙设备Android获取数据,android,bluetooth,bluetooth-lowenergy,Android,Bluetooth,Bluetooth Lowenergy,我正在使用蓝牙LE设备连接android应用程序,并且我能够建立连接。 但在建立连接后,我无法从设备获取更新的回调。 我不确定我做错了什么,因此以下是制造商提供的文档的一部分,我无法理解:- 血氧计在其控制点支持显示同步命令。显示同步命令是写入控制点的2个八位字节的消息。此功能可用于将血氧计的显示与主机设备的显示同步,这有助于操作员确认脉搏血氧计读数已正确接收 其中,第一个八位字节的值为0x61,第二个八位字节的值应介于 5秒和25秒 为了实现这一点,我做了以下工作:- 在LeScanCallb

我正在使用蓝牙LE设备连接android应用程序,并且我能够建立连接。
但在建立连接后,我无法从设备获取更新的回调。 我不确定我做错了什么,因此以下是制造商提供的文档的一部分,我无法理解:-

血氧计在其控制点支持显示同步命令。显示同步命令是写入控制点的2个八位字节的消息。此功能可用于将血氧计的显示与主机设备的显示同步,这有助于操作员确认脉搏血氧计读数已正确接收

其中,第一个八位字节的值为0x61,第二个八位字节的值应介于 5秒和25秒

为了实现这一点,我做了以下工作:-

  • 在LeScanCallback中,我将Bluetooth设备连接到Bluetooth GattCallback

  • 在OnServicesDiscovery中,我编写了以下代码行,我非常怀疑这行代码是否正确 实现这一目标的正确方法,这可能就是我无法从中获取数据的原因 蓝牙设备:-

    蓝牙特征血氧仪特征=

    noninService.getCharacteristic(UUID.fromString(Oximeter_characteristic_uuid));
        BluetoothGattCharacteristic noninControlPointCharacteristic = 
    
       noninService.getCharacteristic(UUID.fromString(Nonin_control_point_characteristic_uuid)); 
    
       oximeterCharacteristic.setValue(0x61, oximeterCharacteristic.FORMAT_SINT16, 1);
        oximeterCharacteristic.setValue(15, oximeterCharacteristic.FORMAT_SINT16, 2);
        noninControlPointCharacteristic.setValue(0x61, noninControlPointCharacteristic.FORMAT_SINT16, 1);
        noninControlPointCharacteristic.setValue(15, noninControlPointCharacteristic.FORMAT_SINT16, 2);
    
    
    gatt.writeCharacteristic(noninControlPointCharacteristic);
        gatt.writeCharacteristic(oximeterCharacteristic);
        gatt.setCharacteristicNotification(oximeterCharacteristic, true);
        gatt.setCharacteristicNotification(noninControlPointCharacteristic, true);
    

  • 我不确定多个设置值将如何工作,但我可以指出,您需要更改一些其他事项。 您希望在写入之前设置通知警报。仅仅调用setCharacteristicNotification也是不够的,您还需要写下通知描述符(您可以在Android蓝牙示例中看到一个这样的示例),然后等待回调通知描述符已写入设备。一旦接到回电话说描述符写入成功,就可以进行写入。
    一旦您对代码进行了这些更改,我建议您重新启动设备和手机,因为Android bluetooth stack往往会进入不稳定的模式,除非您重新启动手机,否则无法恢复。

    您可以将操作系统版本和手机添加到问题中吗?它有助于查明具体的异常情况。“建立连接后,我无法从设备获取更新的回调”。您是否确保正在处理通知特性?(不是读特征和写特征)实际上,你没有提供足够的信息,你是怎么做的?不仅仅是编码。