0

I am trying to receive data from the finger oximeter over bluetooth. Connection works and i receive data in byte[] format, then i convert byte array to string format using UTF-8 encoding and result im getting is in this format:

Ba�J Ba�O Ba�T Ba�W Ba�Z Ba�\ Ba�] Ba�]Ba�]Ba�] Ba�\ Ba�[ Ba�Z Ba�X Ba�W Ba�V Ba�U Ba�T Ba�S Ba�R Ba�Q Ba�Q Ba�P Ba�P Ba�P Ba�O Ba�O Ba�O @a�O @a�O @a�O @a�N @a�N @a�N @a�M @aa�B

And here is my code:

 if(b == delimiter)
 {
   byte[] encodedBytes = new byte[readBufferPosition];
   System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
   final String data = new String(encodedBytes, "UTF-8");
   readBufferPosition = 0;

  handler.post(new Runnable()
  {
      public void run()
      {
         Log.v("Test",data);
      }
  });
 }

What should i do to receive a readable data for displaying?

1 Answer 1

1

Use this constructor of String class:

String dataReceived = new String(mbyteArr, "US-ASCII");

You should, however be sure of the encoding name. My examples used "US-ASCII" and "UTF-8", the two most common encoding standards. May be you need to check the standard with the gadget's documentation.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.