Example usage for android.bluetooth BluetoothGattDescriptor setValue

List of usage examples for android.bluetooth BluetoothGattDescriptor setValue

Introduction

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

Prototype

public boolean setValue(byte[] value) 

Source Link

Document

Updates the locally stored value of this descriptor.

Usage

From source file:com.github.vgoliveira.panificadora.UartService.java

/**
 * Enable TXNotification/*from  ww  w.  j  ava  2 s .  c  o m*/
 *
 * @return
 */

// No est sendo usadada na verso autal
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;
    }
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

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

}

From source file:com.github.w666.ezonwatch.BluetoothLeService.java

/**
 * Enables or disables notification on a give characteristic.
 *
 * @param characteristic Characteristic to act on.
 * @param enabled If true, enable notification.  False otherwise.
 *//*from  w  w w  .  jav  a2 s.  c om*/
public void setCharacteristicNotification(BluetoothGattCharacteristic characteristic, boolean enabled) {
    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAG, "BluetoothAdapter not initialized");
        return;
    }
    mBluetoothGatt.setCharacteristicNotification(characteristic, enabled);
    if (characteristic.getUuid().equals(UUID_EZON_MAIN)) {
        BluetoothGattDescriptor descriptor = characteristic
                .getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
        descriptor.setValue(
                enabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 });
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        mBluetoothGatt.writeDescriptor(descriptor);
    }
}

From source file:com.example.UART.UartService.java

/**
 * Enable TXNotification//from www .j  a v  a  2 s  . c  o m
 *
 * @return 
 */
@SuppressLint("NewApi")
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;
    }
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

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

}

From source file:com.aprilbrother.blueduino.UartService.java

/**
 * Enable TXNotification/*from  w w  w.  ja v  a2 s  .c  o m*/
 * 
 * @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;
    }
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);
    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    mBluetoothGatt.writeDescriptor(descriptor);

}

From source file:com.huiwu.bluetooth.BluetoothService.java

/**
 * Enable TXNotification//from   www . j ava 2  s.  c o m
 *
 * @return
 */
public void enableTXNotification(boolean enable) {
    /*
    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;
    }
    mBluetoothGatt.setCharacteristicNotification(TxChar, true);

    BluetoothGattDescriptor descriptor = TxChar.getDescriptor(CCCD);
    if (enable) {
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    } else {
        descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
    }
    mBluetoothGatt.writeDescriptor(descriptor);

}

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

/**
 * Enable TXNotification/*  w  w w . ja v a 2s  . 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.example.kevin.health.ble.UartService.java

/**
 * Enable TXNotification//from  w w w  .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.sdingba.su.alphabet_demotest.view.lanya.UartService.java

/**
 * Enable TXNotification//from  ww w .ja  v  a  2  s .c  om
 *
 * @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.cqupt.sensor_ble.activity.UartService.java

/**
 * ?//ww  w. j av a 2 s . com
 * 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.chenls.smartlock.UartService.java

/**
 * ?/* w w w.j  a va  2s .  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);

}