code: public synchronized void connect(BluetoothDevice device, boolean past)
              throws IOException, InterruptedException {
          // Cancel any thread attempting to make a connection
          if (mState == STATE_CONNECTING) {
              if (mConnectThread != null) {
                  mConnectThread.cancel();
                  mConnectThread = null;
              }
          }
  
          // Cancel any thread currently running a connection
          if (mEngConnectedThread != null) {
              mEngConnectedThread.cancel();
              mEngConnectedThread = null;
          }
          if (mImpConnectedThread != null) {
              mImpConnectedThread.cancel();
              mImpConnectedThread = null;
          }
  
          mPast = past;
  
          // Start the thread to connect with the given device
          try {
              mConnectThread = new ConnectThread(device);
              mConnectThread.start();
          } catch (IOException e) {
              e.printStackTrace();
              connectionFailed();
              setState(STATE_NONE);
          }
          setState(STATE_CONNECTING);
      }
docs: Start the ConnectThread to initiate a connection to a remote device.
  
  @param device
  The BluetoothDevice to connect
  @param past
  @param secure
  Socket Security type - Secure (true) , Insecure (false)
  @throws InterruptedException
  @throws IOException