如何为rxandroidble的writeCharacteristic设置WRITE_TYPE_NO_响应
这是我的代码。我找不到设置它的方法如何为rxandroidble的writeCharacteristic设置WRITE_TYPE_NO_响应,android,rxandroidble,Android,Rxandroidble,这是我的代码。我找不到设置它的方法 device.establishConnection(false).timeout(1000, TimeUnit.MILLISECONDS).retry(3) .flatMap(rxBleConnection -> rxBleConnection.writeCharacteristic(fromString("0004444-0000-1000-8000-00804444f
device.establishConnection(false).timeout(1000, TimeUnit.MILLISECONDS).retry(3)
.flatMap(rxBleConnection ->
rxBleConnection.writeCharacteristic(fromString("0004444-0000-1000-8000-00804444fb"), hexToBytes(mData))
.timeout(1000, TimeUnit.MILLISECONDS).retry(3
).take(1)
.subscribe(
characteristicValue -> {
Log.e(TAG, "write success " + device.getMacAddress());
},
throwable -> {
Log.e(TAG, "write error " + throwable + " device " + device.getMacAddress());
}
);
在库的当前API中,不容易为每个写入操作使用特定的写入类型,您需要将其设置在旁边
device.establishConnection(false)
.timeout(1000, TimeUnit.MILLISECONDS) // off-topic this seem to be quite short timeout for the action
.retry(3)
.flatMap(RxBleConnection::discoverServices, (rxBleConnection, rxBleDeviceServices) ->
rxBleDeviceServices.getCharacteristic(fromString("0004444-0000-1000-8000-00804444fb"))
.flatMap(characteristic -> {
characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE); // here you set the write type
return rxBleConnection.writeCharacteristic(characteristic, hexToBytes(mData)) // and then execute the write
.timeout(1000, TimeUnit.MILLISECONDS)
.retry(3);
})
)
.flatMap(observable -> observable)
.take(1)
.subscribe(
characteristicValue -> {
Log.e(TAG, "write success " + device.getMacAddress());
},
throwable -> {
Log.e(TAG, "write error " + throwable + " device " + device.getMacAddress());
}
);
正在进行一项添加新API的工作,该API将公开.setWriteType()
方法
注意:并非所有特征都支持
写入类型\u无\u响应
。您可以通过检查BluetoothGattCharacteristic.getProperties()
我的答案对您有用吗?