0

我有一个 android 应用程序将数据发送到蓝牙打印机。第一次打印一切正常,但在第一次打印后出现错误

错误 :

IOException : read failed socket might closed or timeout read

这是我的打印机代码:

    BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
                    .getDefaultAdapter();

            BluetoothDevice secilenYazici = mBluetoothAdapter
                    .getRemoteDevice(sharedPrefs.getString("PRINTER_MAC", ""));

            BluetoothSocket socket = secilenYazici
                    .createRfcommSocketToServiceRecord(MY_UUID);
            mBluetoothAdapter.cancelDiscovery();


            socket.connect();// exception throwing from this line after first pring.

            OutputStream stream = socket.getOutputStream();


// getting printable raw block from webview source.

            String[] rawBlocks = lastHTML.split("<!--RawPrint");
            String rawEnd = rawBlocks[1].split("-->")[0];
            byte[] byteArray = rawEnd.getBytes();


            stream.write(byteArray);



            stream.close();
            socket.close();

我认为关闭后连接丢失,但此代码已经创建了套接字,所以我认为我必须关闭它。

4

1 回答 1

0

我认为这篇文章可能会有所帮助。

问题是你的代码不完整,所以很难看出问题出在哪里。

另外我想我在某处看到运行在 android 4.2 上的三星设备遇到蓝牙问题。我不知道它是否已经修复。

于 2013-09-12T19:34:48.800 回答