Android BluetoothGatt.setCharacteristicNotification()做什么?

Android BluetoothGatt.setCharacteristicNotification()做什么?,android,bluetooth,Android,Bluetooth,阅读时,您可能会认为setCharacteristicNotification启用了可触发特性的通知: 启用或禁用给定事件的通知/指示 特色 但这种方法似乎不能做到这一点?读取BLE,结果是一个多步骤的过程,您必须调用此方法,然后将文件写入描述符 如果是这种情况,那么setCharacteristicNotification本身做什么?需要写入描述符,以便通知远程设备发送通知。setCharactersticNotification仅告知蓝牙堆栈它应将收到的任何通知转发给应用程序。需要写入描述符

阅读时,您可能会认为
setCharacteristicNotification
启用了可触发特性的通知:

启用或禁用给定事件的通知/指示 特色

但这种方法似乎不能做到这一点?读取BLE,结果是一个多步骤的过程,您必须调用此方法,然后将文件写入描述符


如果是这种情况,那么
setCharacteristicNotification
本身做什么?

需要写入描述符,以便通知远程设备发送通知。setCharactersticNotification仅告知蓝牙堆栈它应将收到的任何通知转发给应用程序。

需要写入描述符才能通知远程设备发送通知。setCharactersticNotification仅告知蓝牙堆栈它应将收到的任何通知转发给应用程序。

请阅读。那里的回答者翻阅源代码和文档,发现:

“setCharacteristicNotification仅准备本地服务接收通知。”

我建议为set通知使用包装器函数,因为除了文档不太清楚之外,在本地启用通知接收以及在外围设备上启用通知发送也是一个令人困惑的概念。我会提出一些建议,比如说那些回答者所使用的:

有趣的阅读。那里的回答者翻阅源代码和文档,发现:

“setCharacteristicNotification仅准备本地服务接收通知。”

我建议为set通知使用包装器函数,因为除了文档不太清楚之外,在本地启用通知接收以及在外围设备上启用通知发送也是一个令人困惑的概念。我会提出一些建议,比如说那些回答者所使用的:


嗯,这绝对不是文件上说的。我想这是一个非常糟糕的文档,没有人费心去修复。好吧,这绝对不是文档所说的。我想这是一个非常糟糕的文档,没有人费心去修复。
public boolean setCharacteristicNotification(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic characteristic,boolean enable) {
    Logger.d("setCharacteristicNotification");
    bluetoothGatt.setCharacteristicNotification(characteristic, enable);
    BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID);
    descriptor.setValue(enable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[]{0x00, 0x00});
    return bluetoothGatt.writeDescriptor(descriptor); //descriptor write operation successfully started?

}