Bluetoothプリンターにデータを送信する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();
クローズ後に接続が失われたと思いますが、ソケットはこのコードで既に作成されているので、クローズする必要があると思います。