我有一个 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();
我认为关闭后连接丢失,但此代码已经创建了套接字,所以我认为我必须关闭它。