public void stop() {
        if (mSocketConnecting.get() && mSocket != null) {
            try {
                mSocket.close();
            } catch (IOException e) {
            }
        }
        if (mSocketConnecting.get() && mBluetoothGatt != null) {
            mBluetoothGatt.close();
        }
        if (getDefaultAdapter() != null) {
            getDefaultAdapter().cancelDiscovery();
        }
    }
public void stop ( ) { if ( mSocketConnecting . get ( ) && mSocket != null ) { try { mSocket . close ( ) ; } catch ( IOException e ) { } } if ( mSocketConnecting . get ( ) && mBluetoothGatt != null ) { mBluetoothGatt . close ( ) ; } if ( getDefaultAdapter ( ) != null ) { getDefaultAdapter ( ) . cancelDiscovery ( ) ; } }
Immediately cancel any pending Bluetooth operations.
<p>
The BluetoothSocket.connect() function blocks while waiting for a
connection, but it's thread safe and we can cancel that by calling
close() on it at any time.
<p>
Importantly we don't want to close the socket any other time, because we
want to leave that up to the user of the socket - if you call close()
twice, or close Input/Output streams associated with the socket
simultaneously, it can cause a segfault due to a bug in some Android
Bluetooth stacks. Awesome!