BluetoothGattCharacteristic.setValue连续多次设置

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,添加。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值