Example usage for android.bluetooth BluetoothGattDescriptor ENABLE_NOTIFICATION_VALUE

List of usage examples for android.bluetooth BluetoothGattDescriptor ENABLE_NOTIFICATION_VALUE

Introduction

In this page you can find the example usage for android.bluetooth BluetoothGattDescriptor ENABLE_NOTIFICATION_VALUE.

Prototype

null ENABLE_NOTIFICATION_VALUE

To view the source code for android.bluetooth BluetoothGattDescriptor ENABLE_NOTIFICATION_VALUE.

Click Source Link

Document

Value used to enable notification for a client configuration descriptor

Usage

From source file:ble.AndroidBle.java

@Override
public boolean characteristicNotification(String address, BleGattCharacteristic characteristic) {
    BleRequest request = mService.getCurrentRequest();
    BluetoothGatt gatt = mBluetoothGatts.get(address);
    if (gatt == null || characteristic == null) {
        return false;
    }//from  w  w  w  .ja va  2 s . co  m

    boolean enable = true;
    if (request.type == RequestType.CHARACTERISTIC_STOP_NOTIFICATION) {
        enable = false;
    }
    BluetoothGattCharacteristic c = characteristic.getGattCharacteristicA();
    if (!gatt.setCharacteristicNotification(c, enable)) {
        return false;
    }

    BluetoothGattDescriptor descriptor = c.getDescriptor(BleService.DESC_CCC);
    if (descriptor == null) {
        return false;
    }

    byte[] val_set = null;
    if (request.type == RequestType.CHARACTERISTIC_NOTIFICATION) {
        val_set = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE;
    } else if (request.type == RequestType.CHARACTERISTIC_INDICATION) {
        val_set = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE;
    } else {
        val_set = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE;
    }
    if (!descriptor.setValue(val_set)) {
        return false;
    }

    return gatt.writeDescriptor(descriptor);
}

From source file:com.example.kevin.health.ble.UartService.java

/**
 * Enable TXNotification// w w w .  j a  v a  2 s. c  o  m
 *
 * @return 
 */
public void enableHRNotification() {
    /*
    if (mBluetoothGatt == null) {
       showMessage("mBluetoothGatt null" + mBluetoothGatt);
       broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
       return;
    }
       */
    BluetoothGattService HRService = mBluetoothGatt.getService(HR_SERVICE_UUID);
    if (HRService == null) {
        showMessage("HR service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
        return;
    }
    BluetoothGattCharacteristic TxChar = HRService.getCharacteristic(HR_CHAR_UUID);
    if (TxChar == null) {
        showMessage("HR charateristic not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);
}

From source file:com.ec.android.module.bluetooth40.BluetoothLeService.java

public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;//from  ww w  .  j a va2 s.  c  om
    }
    if (enabled == true) {
        mBluetoothGatt.setCharacteristicNotification(characteristic, true);
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
        if (descriptor != null) {
            //??
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            mBluetoothGatt.writeDescriptor(descriptor);
        }
    } else {
        mBluetoothGatt.setCharacteristicNotification(characteristic, false);
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
        if (descriptor != null) {
            //??
            descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
            mBluetoothGatt.writeDescriptor(descriptor);
        }
    }

}

From source file:com.sdingba.su.alphabet_demotest.view.lanya.UartService.java

/**
 * Enable TXNotification//from  w  ww .  j a v a  2s .c o  m
 *
 * @return
 */
public void enableTXNotification() {
    Log.d(TAG, "SDingBaLanYan : enableTXNotification ");
    if (mBluetoothGatt == null) {
        showMessage("mBluetoothGatt(is null) = null" + mBluetoothGatt);

        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }

    BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID);
    if (RxService == null) {
        showMessage("Rx service not found!---RX_SERVICE_UUID");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID);
    if (TxChar == null) {
        showMessage("==Tx== charateristic not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }

    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);

    mBluetoothGatt.writeDescriptor(descriptor);

}

From source file:com.example.kevin.health.ble.UartService.java

/**
 * Enable TXNotification/*from  w  ww  .  j a  v a 2 s.  c  o  m*/
 *
 * @return 
 */
public void enableTXNotification() {
    /*
    if (mBluetoothGatt == null) {
       showMessage("mBluetoothGatt null" + mBluetoothGatt);
       broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
       return;
    }
       */
    BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID);
    if (RxService == null) {
        showMessage("Rx service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
        return;
    }
    BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID);
    if (TxChar == null) {
        showMessage("Tx charateristic not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT);
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);
}

From source file:com.chenls.smartlock.UartService.java

/**
 * ?//from   ww  w .j  av  a 2 s.c o m
 * Enable TXNotification
 *
 * @return
 */
public void enableTXNotification() {

    if (mBluetoothGatt == null) {
        showMessage("mBluetoothGatt null" + mBluetoothGatt);
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }

    BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID);
    if (RxService == null) {
        showMessage("Rx service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID);
    if (TxChar == null) {
        showMessage("Tx charateristic not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    //characteristic??
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);

}

From source file:com.cqupt.sensor_ble.activity.UartService.java

/**
 * ?//from  w w  w  .  j a  v  a2  s. c  o  m
 * Enable TXNotification
 */
public void enableTXNotification() {

    if (mBluetoothGatt == null) {
        showMessage("mBluetoothGatt null");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }

    BluetoothGattService RxService = mBluetoothGatt.getService(RX_SERVICE_UUID);
    if (RxService == null) {
        showMessage("Rx service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID);
    if (TxChar == null) {
        showMessage("Tx characteristic not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    //characteristic??
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);

}

From source file:com.example.bluetoothmodule.TreadmillService.java

/**
 * Enable TXNotification/*from  w  w w  . ja  va 2s.  c  om*/
 *
 * @return 
 */
private void enableTXNotification() {
    BluetoothGattService RxService = mBluetoothGatt.getService(UUID_TREADMILL_SERVICE);
    if (RxService == null) {
        showMessage("Rx service not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    BluetoothGattCharacteristic TxChar = RxService.getCharacteristic(TX_CHAR_UUID);
    if (TxChar == null) {
        showMessage("Tx charateristic not found!");
        broadcastUpdate(DEVICE_DOES_NOT_SUPPORT_UART);
        return;
    }
    Log.i("Chandler", "RX_SERVICE_UUID");
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);
    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);
}

From source file:com.google.android.apps.forscience.ble.BleFlow.java

public BleFlow enableNotification() {
    actions.add(Action.ENABLE_NOTIF);

    lookupDescriptor(BLE_CLIENT_CONFIG_CHARACTERISTIC);

    actions.add(Action.WRITE_DESC);
    values.add(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    return this;
}

From source file:com.ble.BLService.java

/**
 * Enables or disables notification on a give characteristic.
 * /*from   ww  w .  jav  a 2  s. c om*/
 * @param characteristic
 *            Characteristic to act on.
 * @param enabled
 *            If true, enable notification. False otherwise.
 */
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);

    if (UUID_STM32_ACCELEROMETER_PARAMETER.equals(characteristic.getUuid())) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString(BLGattAttributes.STM32_ACCELEROMETER_PARAMETER));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }

    if (UUID_STM32_WRITE_TO_DEVICE.equals(characteristic.getUuid())) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString(BLGattAttributes.STM32_WRITE_TO_DEVICE));
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }

}