I am using this normal piece of code to open/connect to a Bluetooth socket. While it works perfectly on all devices - only on the newest Nexus with Android 4.2.1 I get this IOException: "read failed socket might closed".
I have tried re-pairing the device, checked the UUID and everything is fine. As mentioned the exact same code works on all other devices. At the moment I am out of ideas where else to look....
private class ConnectBluetoothThread extends Thread { private final BluetoothSocket mmSocket; private final BluetoothDevice mmDevice;
public ConnectBluetoothThread(BluetoothDevice device) {
mmDevice = device;
BluetoothSocket tmp = null;
try {
tmp = mmDevice
.createInsecureRfcommSocketToServiceRecord(MY_UUID);
} catch (IOException e) {
...other code
}
mmSocket = tmp;
}
public void run() {
mBluetoothAdapter.cancelDiscovery();
// Make a connection to the BluetoothSocket
try {
mmSocket.connect(); // <=== this is where the IOException is beeing raised!!!!
} catch (IOException e) {
Log.e(this.getClass().getSimpleName(),
" -> FAILED:", e);
connectionFailed(e);
// Close the socket
try {
mmSocket.close();
} catch (IOException e2) {
}
return;
}
// Reset the ConnectThread because we're done
synchronized (InterBT.this) {
mConnectBluetoothThread = null;
}
// Start the connected thread
connected(mmSocket, mmDevice);
}