code: private BluetoothSocket setupSocket(BluetoothDevice device)
              throws BluetoothException {
          if (device == null) {
              Log.w(TAG, "Can't setup socket -- device is null");
              throw new BluetoothException();
          }
  
          Log.d(TAG, "Scanning services on " + device);
          BluetoothSocket socket;
          try {
              socket = device.createRfcommSocketToServiceRecord(RFCOMM_UUID);
          } catch (IOException e) {
              String error = "Unable to open a socket to device " + device;
              Log.w(TAG, error);
              throw new BluetoothException(error, e);
          }
  
          return socket;
      }
docs: Open an RFCOMM socket to the Bluetooth device.
  <p>
  The device may or may not actually exist, the argument is just a
  reference to it.