Added in API level 18

BluetoothGattService


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

Represents a Bluetooth GATT Service

Gatt Service contains a collection of BluetoothGattCharacteristic, as well as referenced services.

Summary

Constants
static Int

Primary service

static Int

Secondary service (included by primary services)

Inherited constants
Public constructors
BluetoothGattService(uuid: UUID!, serviceType: Int)

Create a new BluetoothGattService.

Public methods
open Boolean

Add a characteristic to this service.

open Boolean

Add an included service to this service.

open BluetoothGattCharacteristic!

Returns a characteristic with a given UUID out of the list of characteristics offered by this service.

open MutableList<BluetoothGattCharacteristic!>!

Returns a list of characteristics included in this service.

open MutableList<BluetoothGattService!>!

Get the list of included GATT services for this service.

open Int

Returns the instance ID for this service

open Int

Get the type of this service (primary/secondary)

open UUID!

Returns the UUID of this service

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

Properties
static Parcelable.Creator<BluetoothGattService!>

MutableList<BluetoothGattCharacteristic!>!

List of characteristics included in this service.

MutableList<BluetoothGattService!>!

List of included services for this service.

Constants

SERVICE_TYPE_PRIMARY

Added in API level 18
static val SERVICE_TYPE_PRIMARY: Int

Primary service

Value: 0

SERVICE_TYPE_SECONDARY

Added in API level 18
static val SERVICE_TYPE_SECONDARY: Int

Secondary service (included by primary services)

Value: 1

Public constructors

BluetoothGattService

Added in API level 18
BluetoothGattService(
    uuid: UUID!,
    serviceType: Int)

Create a new BluetoothGattService.

Parameters
uuid UUID!: The UUID for this service
serviceType Int: The type of this service, android.bluetooth.BluetoothGattService#SERVICE_TYPE_PRIMARY or android.bluetooth.BluetoothGattService#SERVICE_TYPE_SECONDARY

Public methods

addCharacteristic

Added in API level 18
open fun addCharacteristic(characteristic: BluetoothGattCharacteristic!): Boolean

Add a characteristic to this service.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Parameters
characteristic BluetoothGattCharacteristic!: The characteristics to be added
Return
Boolean true, if the characteristic was added to the service

addService

Added in API level 18
open fun addService(service: BluetoothGattService!): Boolean

Add an included service to this service.
For apps targeting Build.VERSION_CODES.R or lower, this requires the Manifest.permission.BLUETOOTH permission which can be gained with a simple <uses-permission> manifest tag.

Parameters
service BluetoothGattService!: The service to be added
Return
Boolean true, if the included service was added to the service

getCharacteristic

Added in API level 18
open fun getCharacteristic(uuid: UUID!): BluetoothGattCharacteristic!

Returns a characteristic with a given UUID out of the list of characteristics offered by this service.

This is a convenience function to allow access to a given characteristic without enumerating over the list returned by getCharacteristics manually.

If a remote service offers multiple characteristics with the same UUID, the first instance of a characteristic with the given UUID is returned.

Return
BluetoothGattCharacteristic! GATT characteristic object or null if no characteristic with the given UUID was found.

getCharacteristics

Added in API level 18
open fun getCharacteristics(): MutableList<BluetoothGattCharacteristic!>!

Returns a list of characteristics included in this service.

Return
MutableList<BluetoothGattCharacteristic!>! Characteristics included in this service

getIncludedServices

Added in API level 18
open fun getIncludedServices(): MutableList<BluetoothGattService!>!

Get the list of included GATT services for this service.

Return
MutableList<BluetoothGattService!>! List of included services or empty list if no included services were discovered.

getInstanceId

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

Returns the instance ID for this service

If a remote device offers multiple services with the same UUID (ex. multiple battery services for different batteries), the instance ID is used to distuinguish services.

Return
Int Instance ID of this service

getType

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

Get the type of this service (primary/secondary)

getUuid

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

Returns the UUID of this service

Return
UUID! UUID of this service

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<BluetoothGattService!>

mCharacteristics

Added in API level 18
protected var mCharacteristics: MutableList<BluetoothGattCharacteristic!>!

List of characteristics included in this service.

mIncludedServices

Added in API level 18
protected var mIncludedServices: MutableList<BluetoothGattService!>!

List of included services for this service.