Android Open Source - BLEService B T L E Command Set Characteristic Notification

From Project

Back to project page BLEService.


The source code is released under:

Copyright (c) 2014, Ratio LLC. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: ...

If you think the Android project BLEService listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.ratio.deviceService.command;
/*from w ww . j  a  va  2 s . c om*/
import java.util.UUID;

import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;

import com.ratio.BTDeviceService.R;
import com.ratio.deviceService.BTLEDeviceManager;
import com.ratio.deviceService.BTLEDeviceManager.BTDeviceInfo;
import com.ratio.deviceService.BTUUID;
import com.ratio.exceptions.DeviceManagerException;
import com.ratio.exceptions.DeviceNameNotFoundException;

 * command queue to set a characteristic on the device
 * @author matt2
public class BTLECommandSetCharacteristicNotification extends BTLECommand {
  protected BluetoothGattCharacteristic mCharacteristic;
  protected boolean            mfEnable;
  public BTLECommandSetCharacteristicNotification(BTLEDeviceManager.BTDeviceInfo  deviceInfo,
                          BluetoothGattCharacteristic   characteristic,
                          boolean              fEnable) {
    mCharacteristic = characteristic;
    mfEnable = fEnable;
  public boolean execute(BTLEDeviceManager deviceManager) throws DeviceManagerException {
        boolean f = mDeviceInfo.getGatt().setCharacteristicNotification(mCharacteristic, mfEnable);
        BluetoothGattDescriptor descriptor = mCharacteristic.getDescriptor(UUID.fromString(BTUUID.CHARACTERISTIC_UPDATE_NOTIFICATION_DESCRIPTOR_UUID));
        descriptor.setValue(mfEnable ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : new byte[] { 0x00, 0x00 });
        f &= mDeviceInfo.getGatt().writeDescriptor(descriptor);
        return f;
  public String toString() {
    return BTLECommandSetCharacteristicNotification.class.getSimpleName() + " addr:" + mDeviceInfo.getDeviceAddress() +
         " characteristic:" + mCharacteristic.getUuid();

Java Source Code List