Open RonnyeryBarbosa opened 4 years ago
Yes, @RonnyeryBarbosa, you solved it? I'm thinking that is an error in socket, that if we want to create a two instances of printing, we should create a different socket to support that. Or we could change the Bluetooth.java, but we can't do that because that file is protected. Another solution is trying to create our library changing the
device.createRfcommSocketToServiceRecord(mMyUuid);
from:
tmp = createBluetoothSocket(mmDevice);
This one is the part of the code that we got our error:
(android/platform/frameworks/base/d6883533e4ac3f73d2fde1db9a1dddf06dac6709/./core/java/android/bluetooth/BluetoothSocket.java)
private int readAll(InputStream is, byte[] b) throws IOException {
int left = b.length;
while(left > 0) {
int ret = is.read(b, b.length - left, left);
if(ret <= 0)
throw new IOException("read failed, socket might closed, read ret: " + ret);
left -= ret;
if(left != 0)
Log.w(TAG, "readAll() looping, read partial size: " + (b.length - left) +
", expect size: " + b.length);
}
return b.length;
}
I've changed the code in Bluetooth.java as follows:
ConnectThread(BluetoothDevice device, boolean insecureConnection) { Bluetooth.this.device = device; try { if (insecureConnection) { Bluetooth.this.socket = device.createInsecureRfcommSocketToServiceRecord(uuid); } else { Bluetooth.this.socket = (BluetoothSocket) device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(device,1); } } catch (IOException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { if (deviceCallback != null) { deviceCallback.onError(Objects.requireNonNull(e.getMessage())); } } }
It worked fine.
this doesn't work for me. any updates?
Any fix on this?
Not a perfect solution but I created a dialog telling my users the app needs a restart. When the app restarts, it resets the socket and fixes the problem. This only needs to run once until a new printer is installed.
This is what worked for me.
I'm trying to print to more than one printer simultaneously, seve.
sometimes it works at other times