Added in API level 18

BluetoothGattCharacteristic


open class BluetoothGattCharacteristic : Parcelable
kotlin.Any
   ↳ android.bluetooth.BluetoothGattCharacteristic

Represents a Bluetooth GATT Characteristic

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.

Summary

Constants
static Int

Characteristic value format type float (32-bit float)

static Int

Characteristic value format type sfloat (16-bit float)

static Int

Characteristic value format type sint16

static Int

Characteristic value format type sint32

static Int

Characteristic value format type sint8

static Int

Characteristic value format type uint16

static Int

Characteristic value format type uint32

static Int

Characteristic value format type uint8

static Int

Characteristic read permission

static Int

Characteristic permission: Allow encrypted read operations

static Int

Characteristic permission: Allow reading with person-in-the-middle protection

static Int

Characteristic write permission

static Int

Characteristic permission: Allow encrypted writes

static Int

Characteristic permission: Allow encrypted writes with person-in-the-middle protection

static Int

Characteristic permission: Allow signed write operations

static Int

Characteristic permission: Allow signed write operations with person-in-the-middle protection

static Int

Characteristic property: Characteristic is broadcastable.

static Int

Characteristic property: Characteristic has extended properties

static Int

Characteristic property: Characteristic supports indication

static Int

Characteristic property: Characteristic supports notification

static Int

Characteristic property: Characteristic is readable.

static Int

Characteristic property: Characteristic supports write with signature

static Int

Characteristic property: Characteristic can be written.

static Int

Characteristic property: Characteristic can be written without response.

static Int

Write characteristic, requesting acknowledgement by the remote device

static Int

Write characteristic without requiring a response by the remote device

static Int

Write characteristic including authentication signature

Inherited constants
Public constructors
BluetoothGattCharacteristic(uuid: UUID!, properties: Int, permissions: Int)

Create a new BluetoothGattCharacteristic.

Public methods
open Boolean

Adds a descriptor to this characteristic.

open Int

open BluetoothGattDescriptor!

Returns a descriptor with a given UUID out of the list of descriptors for this characteristic.

open MutableList<BluetoothGattDescriptor!>!

Returns a list of descriptors for this characteristic.

open Float!
getFloatValue(formatType: Int, offset: Int)

Return the stored value of this characteristic.

open Int

Returns the instance ID for this characteristic.

open Int!
getIntValue(formatType: Int, offset: Int)

Return the stored value of this characteristic.

open Int

Returns the permissions for this characteristic.

open Int

Returns the properties of this characteristic.

open BluetoothGattService!

Returns the service this characteristic belongs to.

open String!

Return the stored value of this characteristic.

open UUID!

Returns the UUID of this characteristic

open ByteArray!

Get the stored value for this characteristic.

open Int

Gets the write type for this characteristic.

open Boolean

Updates the locally stored value of this characteristic.

open Boolean
setValue(value: Int, formatType: Int, offset: Int)

Set the locally stored value of this characteristic.

open Boolean
setValue(mantissa: Int, exponent: Int, formatType: Int, offset: Int)

Set the locally stored value of this characteristic.

open Boolean
setValue(value: String!)

Set the locally stored value of this characteristic.

open Unit
setWriteType(writeType: Int)

Set the write type for this characteristic

open Unit
writeToParcel(out: Parcel, flags: Int)

Properties
static Parcelable.Creator<BluetoothGattCharacteristic!>

MutableList<BluetoothGattDescriptor!>!

List of descriptors included in this characteristic.

Constants

FORMAT_FLOAT

Added in API level 18
static val FORMAT_FLOAT: Int

Characteristic value format type float (32-bit float)

Value: 52

FORMAT_SFLOAT

Added in API level 18
static val FORMAT_SFLOAT: Int

Characteristic value format type sfloat (16-bit float)

Value: 50

FORMAT_SINT16

Added in API level 18
static val FORMAT_SINT16: Int

Characteristic value format type sint16

Value: 34

FORMAT_SINT32

Added in API level 18
static val FORMAT_SINT32: Int

Characteristic value format type sint32

Value: 36

FORMAT_SINT8

Added in API level 18
static val FORMAT_SINT8: Int

Characteristic value format type sint8

Value: 33

FORMAT_UINT16

Added in API level 18
static val FORMAT_UINT16: Int

Characteristic value format type uint16

Value: 18

FORMAT_UINT32

Added in API level 18
static val FORMAT_UINT32: Int

Characteristic value format type uint32

Value: 20

FORMAT_UINT8

Added in API level 18
static val FORMAT_UINT8: Int

Characteristic value format type uint8

Value: 17

PERMISSION_READ

Added in API level 18
static val PERMISSION_READ: Int

Characteristic read permission

Value: 1

PERMISSION_READ_ENCRYPTED

Added in API level 18
static val PERMISSION_READ_ENCRYPTED: Int

Characteristic permission: Allow encrypted read operations

Value: 2

PERMISSION_READ_ENCRYPTED_MITM

Added in API level 18
static val PERMISSION_READ_ENCRYPTED_MITM: Int

Characteristic permission: Allow reading with person-in-the-middle protection

Value: 4

PERMISSION_WRITE

Added in API level 18
static val PERMISSION_WRITE: Int

Characteristic write permission

Value: 16

PERMISSION_WRITE_ENCRYPTED

Added in API level 18
static val PERMISSION_WRITE_ENCRYPTED: Int

Characteristic permission: Allow encrypted writes

Value: 32

PERMISSION_WRITE_ENCRYPTED_MITM

Added in API level 18
static val PERMISSION_WRITE_ENCRYPTED_MITM: Int

Characteristic permission: Allow encrypted writes with person-in-the-middle protection

Value: 64

PERMISSION_WRITE_SIGNED

Added in API level 18
static val PERMISSION_WRITE_SIGNED: Int

Characteristic permission: Allow signed write operations

Value: 128

PERMISSION_WRITE_SIGNED_MITM

Added in API level 18
static val PERMISSION_WRITE_SIGNED_MITM: Int

Characteristic permission: Allow signed write operations with person-in-the-middle protection

Value: 256

PROPERTY_BROADCAST

Added in API level 18
static val PROPERTY_BROADCAST: Int

Characteristic property: Characteristic is broadcastable.

Value: 1

PROPERTY_EXTENDED_PROPS

Added in API level 18
static val PROPERTY_EXTENDED_PROPS: Int

Characteristic property: Characteristic has extended properties

Value: 128

PROPERTY_INDICATE

Added in API level 18
static val PROPERTY_INDICATE: Int

Characteristic property: Characteristic supports indication

Value: 32

PROPERTY_NOTIFY

Added in API level 18
static val PROPERTY_NOTIFY: Int

Characteristic property: Characteristic supports notification

Value: 16

PROPERTY_READ

Added in API level 18
static val PROPERTY_READ: Int

Characteristic property: Characteristic is readable.

Value: 2

PROPERTY_SIGNED_WRITE

Added in API level 18
static val PROPERTY_SIGNED_WRITE: Int

Characteristic property: Characteristic supports write with signature

Value: 64

PROPERTY_WRITE

Added in API level 18
static val PROPERTY_WRITE: Int

Characteristic property: Characteristic can be written.

Value: 8

PROPERTY_WRITE_NO_RESPONSE

Added in API level 18
static val PROPERTY_WRITE_NO_RESPONSE: Int

Characteristic property: Characteristic can be written without response.

Value: 4

WRITE_TYPE_DEFAULT

Added in API level 18
static val WRITE_TYPE_DEFAULT: Int

Write characteristic, requesting acknowledgement by the remote device

Value: 2

WRITE_TYPE_NO_RESPONSE

Added in API level 18
static val WRITE_TYPE_NO_RESPONSE: Int

Write characteristic without requiring a response by the remote device

Value: 1

WRITE_TYPE_SIGNED

Added in API level 18
static val WRITE_TYPE_SIGNED: Int

Write characteristic including authentication signature

Value: 4

Public constructors

BluetoothGattCharacteristic

Added in API level 18
BluetoothGattCharacteristic(
    uuid: UUID!,
    properties: Int,
    permissions: Int)

Create a new BluetoothGattCharacteristic.

Parameters
uuid UUID!: The UUID for this characteristic
properties Int: Properties of this characteristic
permissions Int: Permissions for this characteristic

Public methods

addDescriptor

Added in API level 18
open fun addDescriptor(descriptor: BluetoothGattDescriptor!): Boolean

Adds a descriptor to this characteristic.

Parameters
descriptor BluetoothGattDescriptor!: Descriptor to be added to this characteristic.
Return
Boolean true, if the descriptor was added to the characteristic

describeContents

Added in API level 24
open fun describeContents(): Int
Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR

getDescriptor

Added in API level 18
open fun getDescriptor(uuid: UUID!): BluetoothGattDescriptor!

Returns a descriptor with a given UUID out of the list of descriptors for this characteristic.

Return
BluetoothGattDescriptor! GATT descriptor object or null if no descriptor with the given UUID was found.

getDescriptors

Added in API level 18
open fun getDescriptors(): MutableList<BluetoothGattDescriptor!>!

Returns a list of descriptors for this characteristic.

Return
MutableList<BluetoothGattDescriptor!>! Descriptors for this characteristic

getFloatValue

Added in API level 18
Deprecated in API level 33
open fun getFloatValue(
    formatType: Int,
    offset: Int
): Float!

Deprecated: Use BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic) to get the characteristic value

Return the stored value of this characteristic.

See getValue for details.

Parameters
formatType Int: The format type used to interpret the characteristic value.
offset Int: Offset at which the float value can be found.
Return
Float! Cached value of the characteristic at a given offset or null if the requested offset exceeds the value size.

getInstanceId

Added in API level 18
open fun getInstanceId(): Int

Returns the instance ID for this characteristic.

If a remote device offers multiple characteristics with the same UUID, the instance ID is used to distuinguish between characteristics.

Return
Int Instance ID of this characteristic

getIntValue

Added in API level 18
Deprecated in API level 33
open fun getIntValue(
    formatType: Int,
    offset: Int
): Int!

Deprecated: Use BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic) to get the characteristic value

Return the stored value of this characteristic.

The formatType parameter determines how the characteristic value is to be interpreted. For example, setting 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.

Parameters
formatType Int: The format type used to interpret the characteristic value.
offset Int: Offset at which the integer value can be found.
Return
Int! Cached value of the characteristic or null of offset exceeds value size.

getPermissions

Added in API level 18
open fun getPermissions(): Int

Returns the permissions for this characteristic.

Return
Int Permissions of this characteristic

getProperties

Added in API level 18
open fun getProperties(): Int

Returns the properties of this characteristic.

The properties contain a bit mask of property flags indicating the features of this characteristic.

Return
Int Properties of this characteristic

getService

Added in API level 18
open fun getService(): BluetoothGattService!

Returns the service this characteristic belongs to.

Return
BluetoothGattService! The associated service

getStringValue

Added in API level 18
Deprecated in API level 33
open fun getStringValue(offset: Int): String!

Deprecated: Use BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic) to get the characteristic value

Return the stored value of this characteristic.

See getValue for details.

Parameters
offset Int: Offset at which the string value can be found.
Return
String! Cached value of the characteristic

getUuid

Added in API level 18
open fun getUuid(): UUID!

Returns the UUID of this characteristic

Return
UUID! UUID of this characteristic

getValue

Added in API level 18
Deprecated in API level 33
open fun getValue(): ByteArray!

Deprecated: Use BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic) instead

Get the stored value for this characteristic.

This function returns the stored value for this characteristic as retrieved by calling BluetoothGatt.readCharacteristic. 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.

Return
ByteArray! Cached value of the characteristic

getWriteType

Added in API level 18
open fun getWriteType(): Int

Gets the write type for this characteristic.

Return
Int Write type for this characteristic Value is android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_DEFAULT, android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_NO_RESPONSE, or android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_SIGNED

setValue

Added in API level 18
Deprecated in API level 33
open fun setValue(value: ByteArray!): Boolean

Deprecated: Pass the characteristic value directly into android.bluetooth.BluetoothGatt#writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic,byte[],int)

Updates the locally stored value of this characteristic.

This function modifies the locally stored cached value of this characteristic. To send the value to the remote device, call android.bluetooth.BluetoothGatt#writeCharacteristic to send the value to the remote device.

Parameters
value ByteArray!: New value for this characteristic
Return
Boolean true if the locally stored value has been set, false if the requested value could not be stored locally.

setValue

Added in API level 18
Deprecated in API level 33
open fun setValue(
    value: Int,
    formatType: Int,
    offset: Int
): Boolean

Deprecated: Pass the characteristic value directly into android.bluetooth.BluetoothGatt#writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic,byte[],int)

Set the locally stored value of this characteristic.

See setValue(byte[]) for details.

Parameters
value Int: New value for this characteristic
formatType Int: Integer format type used to transform the value parameter
offset Int: Offset at which the value should be placed
Return
Boolean true if the locally stored value has been set

setValue

Added in API level 18
Deprecated in API level 33
open fun setValue(
    mantissa: Int,
    exponent: Int,
    formatType: Int,
    offset: Int
): Boolean

Deprecated: Pass the characteristic value directly into android.bluetooth.BluetoothGatt#writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic,byte[],int)

Set the locally stored value of this characteristic.

See setValue(byte[]) for details.

Parameters
mantissa Int: Mantissa for this characteristic
exponent Int: exponent value for this characteristic
formatType Int: Float format type used to transform the value parameter
offset Int: Offset at which the value should be placed
Return
Boolean true if the locally stored value has been set

setValue

Added in API level 18
Deprecated in API level 33
open fun setValue(value: String!): Boolean

Deprecated: Pass the characteristic value directly into android.bluetooth.BluetoothGatt#writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic,byte[],int)

Set the locally stored value of this characteristic.

See setValue(byte[]) for details.

Parameters
value String!: New value for this characteristic
Return
Boolean true if the locally stored value has been set

setWriteType

Added in API level 18
open fun setWriteType(writeType: Int): Unit

Set the write type for this characteristic

Setting the write type of a characteristic determines how the android.bluetooth.BluetoothGatt#writeCharacteristic(android.bluetooth.BluetoothGattCharacteristic,byte[],int) function write this characteristic.

Parameters
writeType Int: The write type to for this characteristic. Value is android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_DEFAULT, android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_NO_RESPONSE, or android.bluetooth.BluetoothGattCharacteristic#WRITE_TYPE_SIGNED

writeToParcel

Added in API level 24
open fun writeToParcel(
    out: Parcel,
    flags: Int
): Unit
Parameters
dest The Parcel in which the object should be written. This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES

Properties

CREATOR

Added in API level 24
static val CREATOR: Parcelable.Creator<BluetoothGattCharacteristic!>

mDescriptors

Added in API level 18
protected var mDescriptors: MutableList<BluetoothGattDescriptor!>!

List of descriptors included in this characteristic.