相关疑难解决方法(0)

从android中的蓝牙设备读取数据

我正在使用蓝牙聊天来连接和接收来自蓝牙设备的数据.

我使用以下代码来读取数据:

public void run() {
    byte[] buffer = new byte[1024];
    int bytes;
    Log.v("MR", "start listening....");

    // Keep listening to the InputStream while connected
    while (true) {
        try {
            // Read from the InputStream
            Log.d("MR", "buffer in try");

            bytes = mmInStream.read(buffer);
            Log.d("MR", "input stream :"+(new String(buffer)));
            // Send the obtained bytes to the UI Activity
            mHandler.obtainMessage(Conn.MESSAGE_READ, bytes, -1, buffer).sendToTarget();
            Log.d("MR", "buffer after");

        } catch (Exception e) {
            Log.e("MR", "Error :"+e.getMessage());
            //
            connectionLost();
           // break;
        }

        Log.d("MR", "buffer after while");
    } …
Run Code Online (Sandbox Code Playgroud)

java android bluetooth

15
推荐指数
1
解决办法
3万
查看次数

标签 统计

android ×1

bluetooth ×1

java ×1