读取蓝牙设备数据并打印

时间:2010-11-15 07:23:11

标签: android bluetooth device inputstream

任何人都可以告诉我如何在LogCat中显示蓝牙设备(MyGlucoHealth meter)数据。以下代码:

InputStream is = btSocket.getInputStream();

如何从“是”读取数据并打印出来。 ?

Thanaks, Chenna

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

看看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;
            }
        }
    }