Android Question BLE & ByteConverter problem

wolvo66

Member
Licensed User
Longtime User
I'm having problems decoding a string encoded in a byte array that I am reading from a BT-LE device.
The input string is something like this ":12345678abcd"
The raw data I get from reading the characteristic looks like this: [B@14db8bf7

I have tried using the ByteConverter library, but it doesn't give the expected output, e.g.

B4X:
Sub ble_CharacteristicChanged (Characteristic As BleCharacteristic)
  Log("Get string value: " & Characteristic.GetStringValue(0))
  Dim bc As ByteConverter
  Log("String from byte: " & bc.StringFromBytes(Characteristic.GetValue, "ASCII"))

This gives the output
Get string value: ���
String from byte: ���

I found a Java example, that seems exactly what I need, based on creating a new string e.g.
String s = new String(bytes);
http://www.mkyong.com/java/how-do-convert-byte-array-to-string-in-java/
- but I'm not sure how to do this in B4A?
 
Top