我开发了具有写功能的应用程序。写入功能可以正常工作,但是读取功能无法从BLE设备获得价值,或者我不知道如何获得价值。我想获得此值“ 7B 1E 01 7D 8D 0A”。但是我得到了这个“ 87”。我不知道我在哪里做错了。
这是代码。
@Override
public void onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status);
Log.e("onCharacteristicRead", "Status: " + status);
if (Constant.DEBUG) {
if (status == 0) {
Log.i("JMG", "Read from:" + characteristic.getUuid().toString() + " value: " + bytesToString(characteristic.getValue()));
} else {
Log.i("JMG", "Read fail ,characteristic uuid=:" + characteristic.getUuid().toString() + " status=" + status);
}
}
Log.e("JMG 1", "Read from:" + characteristic.getUuid().toString() + " value: " + bytesToString(characteristic.getValue()));
String value = Arrays.toString(characteristic.getValue());
Log.e("JMG 2", "Read From" + characteristic.getUuid().toString() + "Value" + value);
Intent intent = new Intent(READ_SUCCESS);
intent.putExtra(EXTRA_CHARACTERISTIC, characteristic.getUuid().toString());
intent.putExtra(EXTRA_VALUE, characteristic.getStringValue(0));
intent.putExtra(EXTRA_VALUE_BYTE_ARRAY, characteristic.getValue());
mContext.sendBroadcast(intent);
//COMMENT CODE
/*intent.putExtra(EXTRA_VALUE_STRING, bytesToString(characteristic.getValue()));
intent.putExtra(EXTRA_VALUE, characteristic.getStringValue(0));
intent.putExtra(EXTRA_VALUE_BYTE_ARRAY, bytesToHex(characteristic.getValue()));*/
}