setValue方法是设置BluetoothGattCharacteristic实例上的value的。这个value就是我们要传递的信息。比如我们从android端发送信息的时候,通常这样写:
BluetoothGattCharacteristic characteristic = ……; // 这里根据自己需求获得一个实例
byte[] WriteBytes = new byte[20]; // 因为BLE数据包一次只能传递20个字节的数据
WriteBytes = editTextName.getText().toString().getBytes();
characteristic.setValue(WriteBytes);
// mBluetoothGatt是一个BluetoothGatt实例
mBluetoothGatt.writeCharacteristic(characteristic);
然后BLE会接收到我们WriteBytes的数据。
当 characteristic.setValue(WriteBytes)被连续多次被调用时,比如下面:
BluetoothGattCharacteristic characteristic = ……; // 这里根据自己需求获得一个实例
byte[] WriteBytes = new byte[20]; // 因为BLE数据包一次只能传递20个字节的数据
WriteBytes = editTextName.getText().toString().getBytes();
characteristic.setValue(WriteBytes);
characteristic.setValue(WriteBytes);
characteristic.setValue(WriteBytes);
characteristic.setValue(WriteBytes);
// mBluetoothGatt是一个BluetoothGatt实例
mBluetoothGatt.writeCharacteristic(characteristic);
其实结果并没有不同。BLE只接收到一个WriteBytes的数据。
所以,setValue只是set而已,并不是append,添加。