ANDROID FAILED TO CONNECT BLUETOOTH: read failed, socket might closed or timeout, read ret: -1

  android, bluetooth, java, sockets, uuid

I’m tyrng to create a connection between my smartphone and my arduino. I’m tryng to create an OutputStream for send int value but I’m receiving this error : java.io.IOException: read failed, socket might closed or timeout, read ret: -1

What’s wrong with my code? Is and UUID problem? The UUID is 0000110E-0000-1000-8000-00805F9B34FB , I found that on stackoverflow

    private boolean connectBt() {
    bluetoothAdapter=BluetoothAdapter.getDefaultAdapter();
    bluetoothDevice= bluetoothAdapter.getRemoteDevice(address);
        try {
          socket=bluetoothDevice.createRfcommSocketToServiceRecord(mUUID);
            //socket =(BluetoothSocket) bluetoothDevice.getClass().getMethod("createRfcommSocketToServiceRecord", new Class[] {int.class}).invoke(bluetoothDevice,1);
          socket.connect();
            if(socket.isConnected()){
                try {
                    outputStream=socket.getOutputStream();
                    return true;
                } catch (IOException e) {
                    Log.e("bterr", "ErrORE:" + e.getMessage());
                }
            }
        } catch (Exception e) {
            Log.e("bterr","Errore:"+e.getMessage());
            Toast.makeText(this, "Err:"+e.getMessage(), Toast.LENGTH_LONG).show();
        }
return  false;
}

}

Source: Android Questions

LEAVE A COMMENT