Android BLE 同时通知和指示
Android BLE simultaneous Notification and Indication
所以我的应用程序使用低功耗蓝牙,并且需要使用通知和指示。但是,我无法启用这些指示。是否可以同时启用通知和指示?如果是,下面的方法是否有效?
gattInstance.setCharacteristicNotification(charac, true);
BluetoothGattDescriptor desc = charac.getDescriptor(UUID_CCCD);
desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
desc.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
gattInstance.writeDescriptor(desc);
当你调用desc.setValue
时,你实际上覆盖了之前的值。所以在这里,您编写 CCCD 时仅启用 INDICATION
。
根据 Core Spec v4.2, §3.G.3.3.3.3,CCCD 是一个位域,因此您应该能够写入 16 位小端值 0x0003(似乎没有定义常量为此在 BluetoothGattDescriptor 中)。
所以我的应用程序使用低功耗蓝牙,并且需要使用通知和指示。但是,我无法启用这些指示。是否可以同时启用通知和指示?如果是,下面的方法是否有效?
gattInstance.setCharacteristicNotification(charac, true);
BluetoothGattDescriptor desc = charac.getDescriptor(UUID_CCCD);
desc.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
desc.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
gattInstance.writeDescriptor(desc);
当你调用desc.setValue
时,你实际上覆盖了之前的值。所以在这里,您编写 CCCD 时仅启用 INDICATION
。
根据 Core Spec v4.2, §3.G.3.3.3.3,CCCD 是一个位域,因此您应该能够写入 16 位小端值 0x0003(似乎没有定义常量为此在 BluetoothGattDescriptor 中)。