public class BluetoothAttribute
extends java.lang.Object
BluetoothAttribute
class represents a remote or a local GATT attribute.
This class provides methods to get information on the attribute. It also provides methods to send read or write requests to a remote attribute, and methods to send read or write responses on a local attribute.
Please refer to the child classes documentation for more information.
Modifier and Type | Method and Description |
---|---|
BluetoothService |
getService()
Returns the service to which this attribute belongs.
|
BluetoothUuid |
getUuid()
Returns the UUID of this attribute.
|
boolean |
sendReadRequest()
Sends a read request on this attribute.
|
boolean |
sendReadResponse(BluetoothDevice device,
int status,
byte[] value)
Sends the response to a read request sent by the given device on this attribute.
|
boolean |
sendWriteRequest(byte[] value)
Sends a write request on this attribute with the given value.
|
boolean |
sendWriteResponse(BluetoothDevice device,
int status)
Sends the response to a write request sent by the given device on this attribute.
|
public BluetoothUuid getUuid()
public BluetoothService getService()
This method returns null if this is a local attribute which has not been added to a service.
public boolean sendReadRequest()
java.lang.IllegalStateException
- if this attribute does not belong to a remote device.ClientCallbacks.onReadCompleted(BluetoothCharacteristic, int, byte[])
,
ClientCallbacks.onReadCompleted(BluetoothDescriptor, int, byte[])
public boolean sendWriteRequest(byte[] value)
value
- the value to write.java.lang.IllegalStateException
- if this attribute does not belong to a remote device.ClientCallbacks.onWriteCompleted(BluetoothCharacteristic, int)
,
ClientCallbacks.onWriteCompleted(BluetoothDescriptor, int)
public boolean sendReadResponse(BluetoothDevice device, int status, byte[] value)
device
- the device which sent the request.status
- the status to send back (see BluetoothStatus
).value
- the value to send back.java.lang.IllegalStateException
- if this attribute belongs to a remote device.java.lang.IllegalStateException
- if this attribute has not been added to a servicejava.lang.IllegalStateException
- if the service of this attribute has not been added to an adapter.public boolean sendWriteResponse(BluetoothDevice device, int status)
device
- the device which sent the request.status
- the status to send back (see BluetoothStatus
).java.lang.IllegalStateException
- if this attribute belongs to a remote device.java.lang.IllegalStateException
- if this attribute has not been added to a servicejava.lang.IllegalStateException
- if the service of this attribute has not been added to an adapter.