Android Open Source - BLEService B T L E Command Write Descriptor

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  w w.j a v  a 2s  .c  om*/
import android.bluetooth.BluetoothGattDescriptor;

import com.ratio.BTDeviceService.R;
import com.ratio.deviceService.BTLEDeviceManager;
import com.ratio.exceptions.DeviceManagerException;

 * queued command to write to a BTLE descriptor
 * @author mreynolds
public class BTLECommandWriteDescriptor extends BTLECommand {
  protected BluetoothGattDescriptor mDescriptor;
  public BTLECommandWriteDescriptor(BTLEDeviceManager.BTDeviceInfo  deviceInfo,
                     BluetoothGattDescriptor       descriptor) {
    mDescriptor = descriptor;
  public boolean execute(BTLEDeviceManager deviceManager) throws DeviceManagerException {
    if (!mDeviceInfo.getGatt().writeDescriptor(mDescriptor)) {
      throw new DeviceManagerException(String.format("%s %s %s", deviceManager.getContext().getString(R.string.write_descriptor_failed), 
                                     mDeviceInfo.getDeviceAddress(), mDescriptor.getUuid()));
    return true;
  public String toString() {
    return BTLECommandWriteDescriptor.class.getSimpleName() + " addr:" + mDeviceInfo.getDeviceAddress() +
           " characteristic:" + mDescriptor.getCharacteristic().getUuid() + 
           " descriptor:" + mDescriptor.getUuid();


Java Source Code List