Jose M. Jose M. - 1 year ago 266
Java Question

Buetooth conection failed: read failed, socket might closed or timeout, read ret: -1

I am trying to create a Bluetooth connection.

I can search for nearby devices but when I try to connect I get an error I do not understand:


01-03 00:55:06.909 6654-6654/com.bluetooth.prova3.listdiscovery D/CONNECTTHREAD: Could not close read failed, socket might closed or timeout, read ret: -1

I Have two classes for connect, one that receives the device and execute the connection, an other for make connection.


package com.bluetooth.prova3.listdiscovery;


public class ConexionActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {

//Aqui rebo el dispositiu que he seleccionat per conectarme
Intent intent = getIntent();
BluetoothDevice bluetoothDevice = intent.getExtras().getParcelable("btdevice");
//mostro el nom per la pantalla amb un text view
TextView MacAddress = (TextView)findViewById(;
String aaaa = bluetoothDevice.getName() + "\n" + bluetoothDevice.getAddress();

ConnectThread conexion = new ConnectThread(bluetoothDevice);;

package com.bluetooth.prova3.listdiscovery;


public class ConnectThread extends Thread{
private final BluetoothSocket mmSocket;
private final BluetoothDevice mmDevice;
UUID UUIDaleatorio = UUID.randomUUID();
public ConnectThread(BluetoothDevice device) {
// Use a temporary object that is later assigned to mmSocket,
// because mmSocket is final
BluetoothSocket tmp = null;
mmDevice = device;

// Get a BluetoothSocket to connect with the given BluetoothDevice
try {
// MY_UUID is the app's UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(UUIDaleatorio);
} catch (IOException e) {

Log.d("CONNECTTHREAD", "Could not close connection:" + e.toString());
mmSocket = tmp;

public void run() {
// Cancel discovery because it will slow down the connection
try {
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
} catch (IOException connectException) {
Log.d("CONNECTTHREAD", "Could not close connection:" + connectException.toString());
// Unable to connect; close the socket and get out
try {
} catch (IOException closeException) { Log.d("CONNECTTHREAD", "Could not close connection:" + closeException.toString());}

// Do work to manage the connection (in a separate thread)
// manageConnectedSocket(mmSocket);

/** Will cancel an in-progress connection, and close the socket */
public void cancel() {
try {
} catch (IOException e) { }


Answer Source

Try to use ,


in place of


This should fix the problem. Share your debugging results , if this doesn't fix the issue.

Also , don't generate random UUID(s), try the one below.

UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");