4

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);
}
Marek Sebera
  • 39,650
  • 37
  • 158
  • 244
user387184
  • 10,953
  • 12
  • 77
  • 147
  • I doubt that Android really provides such an illiterate error message. Please correct it to what is really provided. – user207421 Jan 15 '13 at 22:18
  • 2
    Yes you are right, this is illiterate - however, this IS the original error msg. You may see the source code here https://github.com/android/platform_frameworks_base/blob/master/core/java/android/bluetooth/BluetoothSocket.java – user387184 Jan 16 '13 at 10:57
  • I am also stuck with the same problem, any help would be appreciated. – Anil Maddala Feb 02 '13 at 00:53

0 Answers0