Search code examples
androidbluetoothbyteandroid-bluetoothbytestream

Getting data back from bytes


I am continuously getting data from remote bluetooth device which I am storing in a buffer readBuf.

I copy this readBuf to buf.

System.arraycopy(readBuf, 0, buf, 0, readBuf.length);

Now my buf contains data such that -

buf[0] == 0x7D 

buf[1] == 0x51

buf[2] == 0x42 

...and so on...

I want to log this data to know what is coming from remote bluetooth device.

I tried,

Log.i(TAG, "Buffer Data---- "+Arrays.toString(buf));

But it is not giving data correctly to be 7D 51 42 and so on....

How to get the data in order to log ?


Solution

  • This is working fine -

        StringBuffer bufData = new StringBuffer();
        for(byte b : readBuf)
        {
            bufData.append(String.format("%02X", b));
            bufData.append(" ");
        }
    
        Log.i(TAG, "Data Coming from Remote Device---"+bufData.toString());