【发布时间】:2010-11-15 07:23:11
【问题描述】:
任何人都可以告诉我如何在 LogCat 中显示蓝牙设备(MyGlucoHealth 仪表)数据。以下代码:
InputStream is = btSocket.getInputStream();
如何从“is”中读取数据并打印出来。 ?
谢谢, 陈娜
【问题讨论】:
标签: android bluetooth device inputstream
任何人都可以告诉我如何在 LogCat 中显示蓝牙设备(MyGlucoHealth 仪表)数据。以下代码:
InputStream is = btSocket.getInputStream();
如何从“is”中读取数据并打印出来。 ?
谢谢, 陈娜
【问题讨论】:
标签: android bluetooth device inputstream
查看BluetoothChat 示例。 ConnectedThread.run() 从 InputStream 读取数据。
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);
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothChat.MESSAGE_READ, bytes, -1, buffer)
.sendToTarget();
} catch (IOException e) {
Log.e(TAG, "disconnected", e);
connectionLost();
break;
}
}
}
【讨论】: