public class BluetoothGattCharacteristic extends Object implements Parcelable
A GATT characteristic is a basic data element used to construct a GATT service,
BluetoothGattService
. The characteristic contains a value as well as
additional information and optional GATT descriptors, BluetoothGattDescriptor
.
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<BluetoothGattCharacteristic> |
CREATOR |
static int |
FORMAT_FLOAT
Characteristic value format type float (32-bit float)
|
static int |
FORMAT_SFLOAT
Characteristic value format type sfloat (16-bit float)
|
static int |
FORMAT_SINT16
Characteristic value format type sint16
|
static int |
FORMAT_SINT32
Characteristic value format type sint32
|
static int |
FORMAT_SINT8
Characteristic value format type sint8
|
static int |
FORMAT_UINT16
Characteristic value format type uint16
|
static int |
FORMAT_UINT32
Characteristic value format type uint32
|
static int |
FORMAT_UINT8
Characteristic value format type uint8
|
protected List<BluetoothGattDescriptor> |
mDescriptors
List of descriptors included in this characteristic.
|
protected int |
mInstance
Instance ID for this characteristic.
|
protected int |
mKeySize
Key size (default = 16).
|
protected int |
mPermissions
Characteristic permissions.
|
protected int |
mProperties
Characteristic properties.
|
protected BluetoothGattService |
mService
Back-reference to the service this characteristic belongs to.
|
protected UUID |
mUuid
The UUID of this characteristic.
|
protected byte[] |
mValue
The cached value of this characteristic.
|
protected int |
mWriteType
Write type for this characteristic.
|
static int |
PERMISSION_READ
Characteristic read permission
|
static int |
PERMISSION_READ_ENCRYPTED
Characteristic permission: Allow encrypted read operations
|
static int |
PERMISSION_READ_ENCRYPTED_MITM
Characteristic permission: Allow reading with man-in-the-middle protection
|
static int |
PERMISSION_WRITE
Characteristic write permission
|
static int |
PERMISSION_WRITE_ENCRYPTED
Characteristic permission: Allow encrypted writes
|
static int |
PERMISSION_WRITE_ENCRYPTED_MITM
Characteristic permission: Allow encrypted writes with man-in-the-middle
protection
|
static int |
PERMISSION_WRITE_SIGNED
Characteristic permission: Allow signed write operations
|
static int |
PERMISSION_WRITE_SIGNED_MITM
Characteristic permission: Allow signed write operations with
man-in-the-middle protection
|
static int |
PROPERTY_BROADCAST
Characteristic proprty: Characteristic is broadcastable.
|
static int |
PROPERTY_EXTENDED_PROPS
Characteristic property: Characteristic has extended properties
|
static int |
PROPERTY_INDICATE
Characteristic property: Characteristic supports indication
|
static int |
PROPERTY_NOTIFY
Characteristic property: Characteristic supports notification
|
static int |
PROPERTY_READ
Characteristic property: Characteristic is readable.
|
static int |
PROPERTY_SIGNED_WRITE
Characteristic property: Characteristic supports write with signature
|
static int |
PROPERTY_WRITE
Characteristic property: Characteristic can be written.
|
static int |
PROPERTY_WRITE_NO_RESPONSE
Characteristic property: Characteristic can be written without response.
|
static int |
WRITE_TYPE_DEFAULT
Write characteristic, requesting acknoledgement by the remote device
|
static int |
WRITE_TYPE_NO_RESPONSE
Wrtite characteristic without requiring a response by the remote device
|
static int |
WRITE_TYPE_SIGNED
Write characteristic including authentication signature
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
BluetoothGattCharacteristic(UUID uuid,
int properties,
int permissions)
Create a new BluetoothGattCharacteristic.
|
BluetoothGattCharacteristic(UUID uuid,
int instanceId,
int properties,
int permissions)
Create a new BluetoothGattCharacteristic
|
Modifier and Type | Method and Description |
---|---|
boolean |
addDescriptor(BluetoothGattDescriptor descriptor)
Adds a descriptor to this characteristic.
|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
BluetoothGattDescriptor |
getDescriptor(UUID uuid)
Returns a descriptor with a given UUID out of the list of
descriptors for this characteristic.
|
List<BluetoothGattDescriptor> |
getDescriptors()
Returns a list of descriptors for this characteristic.
|
Float |
getFloatValue(int formatType,
int offset)
Return the stored value of this characteristic.
|
int |
getInstanceId()
Returns the instance ID for this characteristic.
|
Integer |
getIntValue(int formatType,
int offset)
Return the stored value of this characteristic.
|
int |
getPermissions()
Returns the permissions for this characteristic.
|
int |
getProperties()
Returns the properties of this characteristic.
|
BluetoothGattService |
getService()
Returns the service this characteristic belongs to.
|
String |
getStringValue(int offset)
Return the stored value of this characteristic.
|
UUID |
getUuid()
Returns the UUID of this characteristic
|
byte[] |
getValue()
Get the stored value for this characteristic.
|
int |
getWriteType()
Gets the write type for this characteristic.
|
void |
setKeySize(int keySize)
Set the desired key size.
|
boolean |
setValue(byte[] value)
Updates the locally stored value of this characteristic.
|
boolean |
setValue(int value,
int formatType,
int offset)
Set the locally stored value of this characteristic.
|
boolean |
setValue(int mantissa,
int exponent,
int formatType,
int offset)
Set the locally stored value of this characteristic.
|
boolean |
setValue(String value)
Set the locally stored value of this characteristic.
|
void |
setWriteType(int writeType)
Set the write type for this characteristic
Setting the write type of a characteristic determines how the
BluetoothGatt.writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic) function write this
characteristic. |
void |
writeToParcel(Parcel out,
int flags)
Flatten this object in to a Parcel.
|
public static final int PROPERTY_BROADCAST
public static final int PROPERTY_READ
public static final int PROPERTY_WRITE_NO_RESPONSE
public static final int PROPERTY_WRITE
public static final int PROPERTY_NOTIFY
public static final int PROPERTY_INDICATE
public static final int PROPERTY_SIGNED_WRITE
public static final int PROPERTY_EXTENDED_PROPS
public static final int PERMISSION_READ
public static final int PERMISSION_READ_ENCRYPTED
public static final int PERMISSION_READ_ENCRYPTED_MITM
public static final int PERMISSION_WRITE
public static final int PERMISSION_WRITE_ENCRYPTED
public static final int PERMISSION_WRITE_ENCRYPTED_MITM
public static final int PERMISSION_WRITE_SIGNED
public static final int PERMISSION_WRITE_SIGNED_MITM
public static final int WRITE_TYPE_DEFAULT
public static final int WRITE_TYPE_NO_RESPONSE
public static final int WRITE_TYPE_SIGNED
public static final int FORMAT_UINT8
public static final int FORMAT_UINT16
public static final int FORMAT_UINT32
public static final int FORMAT_SINT8
public static final int FORMAT_SINT16
public static final int FORMAT_SINT32
public static final int FORMAT_SFLOAT
public static final int FORMAT_FLOAT
protected UUID mUuid
protected int mInstance
protected int mProperties
protected int mPermissions
protected int mKeySize
protected int mWriteType
protected BluetoothGattService mService
protected byte[] mValue
protected List<BluetoothGattDescriptor> mDescriptors
public static final Parcelable.Creator<BluetoothGattCharacteristic> CREATOR
public BluetoothGattCharacteristic(UUID uuid, int properties, int permissions)
Requires android.Manifest.permission#BLUETOOTH
permission.
uuid
- The UUID for this characteristicproperties
- Properties of this characteristicpermissions
- Permissions for this characteristicpublic BluetoothGattCharacteristic(UUID uuid, int instanceId, int properties, int permissions)
public int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void writeToParcel(Parcel out, int flags)
Parcelable
writeToParcel
in interface Parcelable
out
- The Parcel in which the object should be written.flags
- Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE
.public boolean addDescriptor(BluetoothGattDescriptor descriptor)
Requires android.Manifest.permission#BLUETOOTH
permission.
descriptor
- Descriptor to be added to this characteristic.public BluetoothGattService getService()
public UUID getUuid()
public int getInstanceId()
If a remote device offers multiple characteristics with the same UUID, the instance ID is used to distuinguish between characteristics.
public int getProperties()
The properties contain a bit mask of property flags indicating the features of this characteristic.
public int getPermissions()
public int getWriteType()
public void setWriteType(int writeType)
Setting the write type of a characteristic determines how the
BluetoothGatt.writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic)
function write this
characteristic.
writeType
- The write type to for this characteristic. Can be one
of:
WRITE_TYPE_DEFAULT
,
WRITE_TYPE_NO_RESPONSE
or
WRITE_TYPE_SIGNED
.public void setKeySize(int keySize)
public List<BluetoothGattDescriptor> getDescriptors()
public BluetoothGattDescriptor getDescriptor(UUID uuid)
public byte[] getValue()
This function returns the stored value for this characteristic as
retrieved by calling BluetoothGatt.readCharacteristic(android.bluetooth.BluetoothGattCharacteristic)
. The cached
value of the characteristic is updated as a result of a read characteristic
operation or if a characteristic update notification has been received.
public Integer getIntValue(int formatType, int offset)
The formatType parameter determines how the characteristic value
is to be interpreted. For example, settting formatType to
FORMAT_UINT16
specifies that the first two bytes of the
characteristic value at the given offset are interpreted to generate the
return value.
formatType
- The format type used to interpret the characteristic
value.offset
- Offset at which the integer value can be found.public Float getFloatValue(int formatType, int offset)
See getValue()
for details.
formatType
- The format type used to interpret the characteristic
value.offset
- Offset at which the float value can be found.public String getStringValue(int offset)
See getValue()
for details.
offset
- Offset at which the string value can be found.public boolean setValue(byte[] value)
This function modifies the locally stored cached value of this
characteristic. To send the value to the remote device, call
BluetoothGatt.writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic)
to send the value to the
remote device.
value
- New value for this characteristicpublic boolean setValue(int value, int formatType, int offset)
See setValue(byte[])
for details.
value
- New value for this characteristicformatType
- Integer format type used to transform the value parameteroffset
- Offset at which the value should be placedpublic boolean setValue(int mantissa, int exponent, int formatType, int offset)
See setValue(byte[])
for details.
mantissa
- Mantissa for this characteristicexponent
- exponent value for this characteristicformatType
- Float format type used to transform the value parameteroffset
- Offset at which the value should be placedpublic boolean setValue(String value)
See setValue(byte[])
for details.
value
- New value for this characteristic