app/libs/btcar/BluetoothChatService.java
public synchronized void connected(BluetoothSocket socket, BluetoothDevice
            device, final String socketType) {
        if (D) Log.d(TAG, "connected, Socket Type:" + socketType);

        // Cancel the thread that completed the connection
        if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}

        // Cancel any thread currently running a connection
        if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}

        // Cancel the accept thread because we only want to connect to one device
        if (mSecureAcceptThread != null) {
            mSecureAcceptThread.cancel();
            mSecureAcceptThread = null;
        }
        if (mInsecureAcceptThread != null) {
            mInsecureAcceptThread.cancel();
            mInsecureAcceptThread = null;
        }

        // Start the thread to manage the connection and perform transmissions
        mConnectedThread = new ConnectedThread(socket, socketType);
        mConnectedThread.start();

        // Send the name of the connected device back to the UI Activity
        Message msg = mHandler.obtainMessage(BTcar.MESSAGE_DEVICE_NAME);
        Bundle bundle = new Bundle();
        bundle.putString(BTcar.DEVICE_NAME, device.getName());
        msg.setData(bundle);
        mHandler.sendMessage(msg);

        setState(STATE_CONNECTED);
    }
/**
     * Start the ConnectedThread to begin managing a Bluetooth connection
     * @param socket  The BluetoothSocket on which the connection was made
     * @param device  The BluetoothDevice that has been connected
     */
Start the ConnectedThread to begin managing a Bluetooth connection
@param socket  The BluetoothSocket on which the connection was made
@param device  The BluetoothDevice that has been connected
Start the ConnectedThread to begin managing a Bluetooth connection @param socket The BluetoothSocket on which the connection was made @param device The BluetoothDevice that has been connected
public synchronized void connected(BluetoothSocket socket, BluetoothDevice
            device, final String socketType) {
        if (D) Log.d(TAG, "connected, Socket Type:" + socketType);
        if (mConnectThread != null) {mConnectThread.cancel(); mConnectThread = null;}
        if (mConnectedThread != null) {mConnectedThread.cancel(); mConnectedThread = null;}
        if (mSecureAcceptThread != null) {
            mSecureAcceptThread.cancel();
            mSecureAcceptThread = null;
        }
        if (mInsecureAcceptThread != null) {
            mInsecureAcceptThread.cancel();
            mInsecureAcceptThread = null;
        }
        mConnectedThread = new ConnectedThread(socket, socketType);
        mConnectedThread.start();
        Message msg = mHandler.obtainMessage(BTcar.MESSAGE_DEVICE_NAME);
        Bundle bundle = new Bundle();
        bundle.putString(BTcar.DEVICE_NAME, device.getName());
        msg.setData(bundle);
        mHandler.sendMessage(msg);
        setState(STATE_CONNECTED);
    }
public synchronized void connected ( BluetoothSocket socket , BluetoothDevice device , final String socketType ) { if ( D ) Log . d ( TAG , "connected, Socket Type:" + socketType ) ; if ( mConnectThread != null ) { mConnectThread . cancel ( ) ; mConnectThread = null ; } if ( mConnectedThread != null ) { mConnectedThread . cancel ( ) ; mConnectedThread = null ; } if ( mSecureAcceptThread != null ) { mSecureAcceptThread . cancel ( ) ; mSecureAcceptThread = null ; } if ( mInsecureAcceptThread != null ) { mInsecureAcceptThread . cancel ( ) ; mInsecureAcceptThread = null ; } mConnectedThread = new ConnectedThread ( socket , socketType ) ; mConnectedThread . start ( ) ; Message msg = mHandler . obtainMessage ( BTcar . MESSAGE_DEVICE_NAME ) ; Bundle bundle = new Bundle ( ) ; bundle . putString ( BTcar . DEVICE_NAME , device . getName ( ) ) ; msg . setData ( bundle ) ; mHandler . sendMessage ( msg ) ; setState ( STATE_CONNECTED ) ; }
Start the ConnectedThread to begin managing a Bluetooth connection
 @param socket  The BluetoothSocket on which the connection was made
 @param device  The BluetoothDevice that has been connected
Start the ConnectedThread to begin managing a Bluetooth connection @param socket The BluetoothSocket on which the connection was made @param device The BluetoothDevice that has been connected
// Cancel the thread that completed the connection // Cancel any thread currently running a connection // Cancel the accept thread because we only want to connect to one device // Start the thread to manage the connection and perform transmissions // Send the name of the connected device back to the UI Activity