我有一个硬件设备,它每秒通过蓝牙连接向我发送一些数据。当我收到数据时,有时会收到2条消息,有时会收到1条消息。有人可以向我解释原因吗?
日志
I/BluetoothChatService: 3
I/BluetoothChatService: 1
I/BluetoothChatService: 3
I/BluetoothChatService: 1
I/BluetoothChatService: 31
I/BluetoothChatService: 31
I/BluetoothChatService: 31
I/BluetoothChatService: 31
阅读
public void run () {
byte [] buffer = new byte[1024];
int numBytes;
while (true) {
try {
numBytes = mmInStream.read(buffer);
mHandler.obtainMessage(Constants.MESSAGE_READ, numBytes, -1, buffer)
.sendToTarget();
String readMessage = new String(buffer, 0, numBytes);
Log.i(TAG, readMessage);
} catch (IOException e) {
e.printStackTrace();
}
}
}