我很困惑如何使用Android应用程序向CC2540写入20个字节。
我可以使用下面的代码轻松地写一个字节(到2540的一个字节特征):
if ((charaProp | BluetoothGattCharacteristic.PROPERTY_WRITE) > 0) {
// If there is an active notification on a characteristic, clear
// it first so it doesn't update the data field on the user interface.
if (mNotifyCharacteristic != null) {
mBluetoothLeService.setCharacteristicNotification(mNotifyCharacteristic, false);
mNotifyCharacteristic = null;
}
byte[] writev = {0x0c};
characteristic.setValue(writev);
mBluetoothLeService.writeCharacteristic(characteristic);
}
但是如果我想将20个字节写入2540的20字节特征,那么通过如下更改代码似乎是错误的:
String Mysend = "11111111111111111111";//20bytes
byte[] writev = Mysend.getBytes();
characteristic.setValue(writev);
mBluetoothLeService.writeCharacteristic(characteristic);
那么,我如何使用Android BLE应用程序向CC2540写入20个字节?
谢谢! 卡隆
答案 0 :(得分:0)
很难说出现了什么问题,但有些事情要尝试:
BluetoothGattCallback.onCharacteristicWrite()
的gattStatus,因为它可能会告诉您它失败的原因。