Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为rxandroidble的writeCharacteristic设置WRITE_TYPE_NO_响应_Android_Rxandroidble - Fatal编程技术网

如何为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()

我的答案对您有用吗?