public class BluetoothCharacteristic extends BluetoothAttribute
BluetoothCharacteristic
class represents a remote or a local GATT characteristic.
Remote characteristics may be retrieved from a Bluetooth device by discovering its services
and getting their characteristics
.
Local characteristics may be created by using the class constructor
and
added
to a local service.
This class provides methods to get information on the characteristic. It also provides methods to add descriptors and to send notifications on a local characteristic.
Constructor and Description |
---|
BluetoothCharacteristic(BluetoothUuid uuid,
int properties,
int permissions)
Creates a local characteristic with the given UUID, properties and permissions.
|
Modifier and Type | Method and Description |
---|---|
void |
addDescriptor(BluetoothDescriptor descriptor)
Adds a descriptor to this characteristic.
|
BluetoothDescriptor |
findDescriptor(BluetoothUuid descriptorUuid)
Finds the descriptor of this characteristic which matches the given UUID.
|
BluetoothDescriptor[] |
getDescriptors()
Returns the list of descriptors of this characteristic.
|
int |
getProperties()
Returns the properties of this characteristic.
|
boolean |
sendNotification(BluetoothDevice device,
byte[] value,
boolean confirm)
Sends a notification on this characteristic to the given device with the given value.
|
getService, getUuid, sendReadRequest, sendReadResponse, sendWriteRequest, sendWriteResponse
public BluetoothCharacteristic(BluetoothUuid uuid, int properties, int permissions)
This characteristic may then be added
to a local service.
uuid
- the characteristic UUID.properties
- the characteristic properties (see BluetoothProperties
).permissions
- the characteristic permissions (see BluetoothPermissions
).public void addDescriptor(BluetoothDescriptor descriptor)
descriptor
- the descriptor to add.java.lang.IllegalStateException
- if this characteristic belongs to a remote device.java.lang.IllegalStateException
- if the service of this characteristic has already been added to an adapter.java.lang.IllegalStateException
- if the descriptor has already been added to a characteristic.public int getProperties()
BluetoothProperties
).public BluetoothDescriptor[] getDescriptors()
public BluetoothDescriptor findDescriptor(BluetoothUuid descriptorUuid)
If multiple descriptors have the same UUID, any of them may be returned.
descriptorUuid
- the UUID of the descriptor to find.public boolean sendNotification(BluetoothDevice device, byte[] value, boolean confirm)
device
- the device to which the notification should be sent.value
- the value to send.confirm
- true to request a confirmation (GATT indication), false otherwise (GATT notification).java.lang.IllegalStateException
- if this characteristic belongs to a remote device.java.lang.IllegalStateException
- if this characteristic has not been added to a servicejava.lang.IllegalStateException
- if the service of this characteristic has not been added to an adapter.ServerCallbacks.onNotificationSent(BluetoothCharacteristic, BluetoothDevice, boolean)