-1

We receive from bluetooth device this output: byte[] bytes = intent.getStringExtra(BluetoothLeService.EXTRA_DATA).getBytes();

and the output is: enter image description here

How I can transform bytes[] to String[] in format HEX without losing "CE" chars in the picture?

ben75
  • 29,217
  • 10
  • 88
  • 134
Daniel Ortiz
  • 23
  • 1
  • 5

1 Answers1

5

If your bytes are just plain text, then you can do

new String(bytes, "UTF-8");

If your bytes create a hex string, convert that hex string to another byte[] by doing

new String(DatatypeConverter.parseHexBinary(new String(bytes)), "UTF-8")
samczsun
  • 1,014
  • 6
  • 16
  • I can call DatatypeConverter in android? – Daniel Ortiz Jan 05 '16 at 14:21
  • Ah, my bad. You can either shade a library which supports conversion or use a method from another StackOverflow answer such as [this one](http://stackoverflow.com/a/19119453/4490686) – samczsun Jan 05 '16 at 14:27