0
嵌入式系统项目中,我将得到我的微控制器到Android设备使用蓝牙模块的一些反应,我不能得到这一行的字节bytes = "mmInStream.read(buffer)"
.. 当我转换字节[]缓冲成字符串使用这个 String data=new String(bytes)
我没有得到我从我的微控制器正确发送的数据。有时charactors缺少..Java输入流读取()没有得到完整的字节阵列数据
public void run() {
Log.i(TAG, "BEGIN mConnectedThread");
byte[] buffer = new byte[1024];
int bytes;
// Keep listening to the InputStream while connected
while (true) {
try {
// Read from the InputStream
bytes = mmInStream.read(buffer);
String data=new String(bytes);
System.out.println(data);
// Send the obtained bytes to the UI Activity
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}
请帮我
使用新的字符串(缓冲区,0,字节)而不是新的字符串(字节),并且数据应该正确显示 – Paul 2015-03-19 11:39:26