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 ) ; }
Start the ConnectThread to initiate a connection to a remote device .