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:Main.java

public static boolean disableNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    BluetoothGattDescriptor descriptor = configDescriptor(characteristic);
    descriptor.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
    return gatt.writeDescriptor(descriptor) && gatt.setCharacteristicNotification(characteristic, false);
}

From source file:Main.java

public static boolean enableNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
    BluetoothGattDescriptor descriptor = configDescriptor(characteristic);
    descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    return gatt.setCharacteristicNotification(characteristic, true) && gatt.writeDescriptor(descriptor);
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
static boolean setCharacteristicNotification(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic,
        boolean isEnabled) {
    if (characteristic != null) {
        gatt.setCharacteristicNotification(characteristic, isEnabled);
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(DEVICE_CONFIG_CHARACTERISTIC);
        if (descriptor != null) {
            descriptor.setValue(
                    isEnabled ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 });
            return gatt.writeDescriptor(descriptor);
        } else/*from  w w  w  .  j a  va  2s.c  o  m*/
            return false;
    } else
        return false;
}

From source file:net.emilymaier.movebot.HeartFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.main_heart, container, false);
    heartScan = (Button) rootView.findViewById(R.id.heartScan);
    heartList = (ListView) rootView.findViewById(R.id.heartList);
    heartDevices = new ArrayList<>();
    heartListAdapter = new ArrayAdapter<>(act, android.R.layout.simple_list_item_1, heartDevices);
    heartList.setAdapter(heartListAdapter);
    heartList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from ww  w  .  ja v  a  2  s .co  m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d("HeartFragment", "Selecting device");
            for (HeartDevice device : heartDevices) {
                device.bluetoothGatt.setCharacteristicNotification(device.characteristic, false);
            }
            HeartDevice device = heartDevices.get(position);
            device.bluetoothGatt.setCharacteristicNotification(device.characteristic, true);
            BluetoothGattDescriptor descriptor = device.characteristic
                    .getDescriptor(UUID.fromString("00002902-0000-1000-8000-00805f9b34fb"));
            descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            device.bluetoothGatt.writeDescriptor(descriptor);
        }
    });
    heartScan.setOnClickListener(this);
    return rootView;
}

From source file:com.example.alexanderbolinsky.ble_uart_remote.UartService.java

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

    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.megster.cordova.rfduino.Peripheral.java

@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
    Log.d(TAG, "gatt " + gatt);
    Log.d(TAG, "status " + status);
    super.onServicesDiscovered(gatt, status);

    BluetoothGattService service = gatt.getService(RFDUINO_SERVICE_UUID);
    Log.d(TAG, "service " + service);

    BluetoothGattCharacteristic receiveCharacteristic = service.getCharacteristic(RECEIVE_CHARACTERISTIC_UUID);
    sendCharacteristic = service.getCharacteristic(SEND_CHARACTERISTIC_UUID);
    disconnectCharacteristic = service.getCharacteristic(DISCONNECT_CHARACTERISTIC_UUID);

    if (receiveCharacteristic != null) {
        gatt.setCharacteristicNotification(receiveCharacteristic, true);

        BluetoothGattDescriptor receiveConfigDescriptor = receiveCharacteristic
                .getDescriptor(CLIENT_CHARACTERISTIC_CONFIGURATION_UUID);
        if (receiveConfigDescriptor != null) {
            receiveConfigDescriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(receiveConfigDescriptor);
        } else {/*from  w w  w  . j  a  va2  s. com*/
            LOG.e(TAG, "Receive Characteristic can not be configured.");
        }
    } else {
        LOG.e(TAG, "Receive Characteristic is missing.");
    }

    // call the success callback for connect
    PluginResult result = new PluginResult(PluginResult.Status.OK);
    result.setKeepCallback(true);
    connectCallback.sendPluginResult(result);
}

From source file:com.shenqu.jlplayer.nRFUARTv2.UartService.java

/**
 * Enable TXNotification//from w  w  w  .ja va 2s .c om
 *
 * @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.example.alan.bikelog.UartService.java

/**
 * Enable TXNotification//from  w  ww . j  a  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.cardiograph.service.UartService.java

/**
 * Enable TXNotification//from  www  . j  av  a2 s  .  c om
 *
 * @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.pandadentist.service.UartService.java

/**
 * Enable TXNotification// w  w w .  j a  va2  s .com
 *
 * @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);

}