private synchronized void setConnectionState(final State newState, final boolean broadCast) {
        Log.i(TAG, "Setting internal state to " + newState);
        mConnectionState = newState;

        final String broadcastAction;

        switch (newState) {
            case CONNECTED:
                broadcastAction = ACTION_GATT_CONNECTED;
                break;
            case CONNECTING:
                broadcastAction = ACTION_GATT_CONNECTING;
                break;
            case DISCONNECTED:
                broadcastAction = ACTION_GATT_DISCONNECTED;
                break;
            default:
                throw new IllegalArgumentException("Unknown state: " + newState);
        }

        if (broadCast) {
            Log.i(TAG, "Broadcasting " + broadcastAction);
            broadcastUpdate(broadcastAction);
        }

    }
Connects to the GATT server hosted on the Bluetooth LE device.

@param address The device address of the destination device.
@return Return true if the connection is initiated successfully. The connection result
is reported asynchronously through the
{@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)}
callback.
sample_app/src/main/java/uk/co/alt236/btlescan/services/BluetoothLeService.java