# Class GattCharacteristic

java.lang.Object
com.codename1.bluetooth.gatt.GattCharacteristic

public class GattCharacteristic extends Object

A characteristic of a remote `GattService` -- the unit of data exchange with a BLE peripheral. Read, write and subscribe operations are routed through the owning peripheral's internal operation queue, so any number of calls may be issued concurrently; they execute in order.

Instances are constructed by the port during service discovery; application code never creates them.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `PROPERTY_BROADCAST`
  The characteristic supports broadcast (bit `0x01`).
  `static final int`
  `PROPERTY_EXTENDED_PROPS`
  The characteristic has extended properties (bit `0x80`).
  `static final int`
  `PROPERTY_INDICATE`
  The characteristic supports indications (bit `0x20`).
  `static final int`
  `PROPERTY_NOTIFY`
  The characteristic supports notifications (bit `0x10`).
  `static final int`
  `PROPERTY_READ`
  The characteristic can be read (bit `0x02`).
  `static final int`
  `PROPERTY_SIGNED_WRITE`
  The characteristic supports signed writes (bit `0x40`).
  `static final int`
  `PROPERTY_WRITE`
  The characteristic can be written with response (bit `0x08`).
  `static final int`
  `PROPERTY_WRITE_WITHOUT_RESPONSE`
  The characteristic can be written without response (bit `0x04`).

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GattCharacteristic(GattService service, BluetoothUuid uuid, int properties, int instanceId)`
  Constructed by ports during service discovery; not application API.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addDescriptor(GattDescriptor descriptor)`
  Called by ports while building the discovered GATT database; not application API.
  `boolean`
  `canIndicate()`
  `true` when `PROPERTY_INDICATE` is set.
  `boolean`
  `canNotify()`
  `true` when `PROPERTY_NOTIFY` is set.
  `boolean`
  `canRead()`
  `true` when `PROPERTY_READ` is set.
  `boolean`
  `canWrite()`
  `true` when `PROPERTY_WRITE` is set.
  `boolean`
  `canWriteWithoutResponse()`
  `true` when `PROPERTY_WRITE_WITHOUT_RESPONSE` is set.
  `GattDescriptor`
  `getDescriptor(BluetoothUuid uuid)`
  The first descriptor with the given UUID, or `null`.
  `List<GattDescriptor>`
  `getDescriptors()`
  The descriptors of this characteristic, in discovery order.
  `int`
  `getInstanceId()`
  Disambiguates multiple instances of the same characteristic UUID within one service.
  `int`
  `getProperties()`
  The raw `PROPERTY_*` bitmask as advertised by the peripheral.
  `GattService`
  `getService()`
  The service this characteristic belongs to.
  `BluetoothUuid`
  `getUuid()`
  The UUID identifying this characteristic.
  `boolean`
  `isSubscribed()`
  `true` while notifications/indications are armed for this characteristic.
  `AsyncResource<byte[]>`
  `read()`
  Reads the current value.
  `AsyncResource<Boolean>`
  `subscribe(GattNotificationListener l)`
  Subscribes to value changes.
  `String`
  `toString()`
  Returns a string representation of the object.
  `AsyncResource<Boolean>`
  `unsubscribe(GattNotificationListener l)`
  Removes a listener added via `subscribe(GattNotificationListener)`.
  `AsyncResource<Boolean>`
  `write(byte[] value)`
  Writes the value with response.
  `AsyncResource<Boolean>`
  `writeWithoutResponse(byte[] value)`
  Writes the value without response.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### PROPERTY_BROADCAST

    public static final int PROPERTY_BROADCAST
    The characteristic supports broadcast (bit `0x01`).
    See Also:
      - Constant Field Values

  - ### PROPERTY_READ

    public static final int PROPERTY_READ
    The characteristic can be read (bit `0x02`).
    See Also:
      - Constant Field Values

  - ### PROPERTY_WRITE_WITHOUT_RESPONSE

    public static final int PROPERTY_WRITE_WITHOUT_RESPONSE
    The characteristic can be written without response (bit `0x04`).
    See Also:
      - Constant Field Values

  - ### PROPERTY_WRITE

    public static final int PROPERTY_WRITE
    The characteristic can be written with response (bit `0x08`).
    See Also:
      - Constant Field Values

  - ### PROPERTY_NOTIFY

    public static final int PROPERTY_NOTIFY
    The characteristic supports notifications (bit `0x10`).
    See Also:
      - Constant Field Values

  - ### PROPERTY_INDICATE

    public static final int PROPERTY_INDICATE
    The characteristic supports indications (bit `0x20`).
    See Also:
      - Constant Field Values

  - ### PROPERTY_SIGNED_WRITE

    public static final int PROPERTY_SIGNED_WRITE
    The characteristic supports signed writes (bit `0x40`).
    See Also:
      - Constant Field Values

  - ### PROPERTY_EXTENDED_PROPS

    public static final int PROPERTY_EXTENDED_PROPS
    The characteristic has extended properties (bit `0x80`).
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### GattCharacteristic

    public GattCharacteristic(GattService service, BluetoothUuid uuid, int properties, int instanceId)
    Constructed by ports during service discovery; not application API.

- ## Method Details

  - ### getUuid

    public BluetoothUuid getUuid()
    The UUID identifying this characteristic.

  - ### getService

    public GattService getService()
    The service this characteristic belongs to.

  - ### getProperties

    public int getProperties()
    The raw `PROPERTY_*` bitmask as advertised by the peripheral.

  - ### getInstanceId

    public int getInstanceId()
    Disambiguates multiple instances of the same characteristic UUID within one service.

  - ### canRead

    public boolean canRead()
    `true` when `PROPERTY_READ` is set.

  - ### canWrite

    public boolean canWrite()
    `true` when `PROPERTY_WRITE` is set.

  - ### canWriteWithoutResponse

    public boolean canWriteWithoutResponse()
    `true` when `PROPERTY_WRITE_WITHOUT_RESPONSE` is set.

  - ### canNotify

    public boolean canNotify()
    `true` when `PROPERTY_NOTIFY` is set.

  - ### canIndicate

    public boolean canIndicate()
    `true` when `PROPERTY_INDICATE` is set.

  - ### getDescriptors

    public List<GattDescriptor> getDescriptors()
    The descriptors of this characteristic, in discovery order.

  - ### getDescriptor

    public GattDescriptor getDescriptor(BluetoothUuid uuid)
    The first descriptor with the given UUID, or `null`.

  - ### addDescriptor

    public void addDescriptor(GattDescriptor descriptor)
    Called by ports while building the discovered GATT database; not application API.

  - ### read

    public AsyncResource<byte[]> read()
    Reads the current value. Resolves with the raw bytes on the EDT or fails with a `BluetoothException`.

  - ### write

    public AsyncResource<Boolean> write(byte[] value)
    Writes the value with response. Resolves `true` on the EDT once the peripheral acknowledged the write.

  - ### writeWithoutResponse

    public AsyncResource<Boolean> writeWithoutResponse(byte[] value)
    Writes the value without response. Resolves `true` once the value was queued to the controller -- there is no remote acknowledgement.

  - ### subscribe

    public AsyncResource<Boolean> subscribe(GattNotificationListener l)
    Subscribes to value changes. The first listener triggers the CCCD write that arms notifications (indications are used when the characteristic only supports `PROPERTY_INDICATE`); the returned resource resolves `true` once armed. Additional listeners resolve immediately. Values stream to the listener on the EDT until `unsubscribe(GattNotificationListener)` or disconnection.

  - ### unsubscribe

    public AsyncResource<Boolean> unsubscribe(GattNotificationListener l)
    Removes a listener added via `subscribe(GattNotificationListener)`. When the last listener is removed the CCCD is written to disarm notifications; the returned resource resolves once done.

  - ### isSubscribed

    public boolean isSubscribed()
    `true` while notifications/indications are armed for this characteristic.

  - ### toString

    public String toString()
    Description copied from class: `Object`
    Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
    Overrides:
      `toString` in class `Object`