Getting Java.io.ioexception: Read Failed, Socket Might Closed Or Timeout, Read Ret: -1 While Printing Via Bluetooth Printer
Code is working fine for first time only, if i am trying to connect it again it is throwing this exception: read failed, socket might closed or timeout, read ret: -1 This is my f
Solution 1:
You should close your socket after using it :
publicbooleanopenBT(Context context)throws IOException {
try {
// Standard SerialPortService IDUUIDuuid= UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
mmSocket = mmDevice.createRfcommSocketToServiceRecord(uuid);
mBluetoothAdapter.cancelDiscovery();
mmSocket.connect();
mmOutputStream = newDataOutputStream(mmSocket.getOutputStream());
mmInputStream = newDataInputStream(mmSocket.getInputStream());
mmSocket.close(); //Socket closed
} catch (NullPointerException e) {
e.printStackTrace();
returnfalse;
} catch (Exception e) {
e.printStackTrace();
returnfalse;
}
returntrue;}
Solution 2:
Check your UUID and try this if you don't know the UUID:
UUIDuuidSting=null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
uuidSting = bluetoothDevice.getUuids()[0].getUuid();
}
instead use:
UUIDuuid= UUID.fromString("00001101-0000-1000-8000-00805f9b34fb");
Post a Comment for "Getting Java.io.ioexception: Read Failed, Socket Might Closed Or Timeout, Read Ret: -1 While Printing Via Bluetooth Printer"