Android InputStream dropping first two bytes (modified BluetoothChat)

后端 未结 5 928
长情又很酷
长情又很酷 2020-12-05 12:47

I\'ve used code from BluetoothChat example to send and receive byte data from a Bluetooth Scale. The scale receives the command from the device, then sends back a byte array

5条回答
  •  粉色の甜心
    2020-12-05 12:54

    I was in the same position as you a few weeks ago.

    I discovered The read count is random when using read(buffer). So you will never truly predict how big the next data packet will be.

    The simple fix for me was to read a single byte at a time using read() and add it to a local buffer until every byte is received.

    Hope this helps.

提交回复
热议问题