Skip to content

Most visited

Recently visited

navigation
Added in API level 18

BluetoothGattService

public class BluetoothGattService
extends Object implements Parcelable

java.lang.Object
   ↳ android.bluetooth.BluetoothGattService


Represents a Bluetooth GATT Service

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

Summary

Constants

int SERVICE_TYPE_PRIMARY

Primary service

int SERVICE_TYPE_SECONDARY

Secondary service (included by primary services)

Inherited constants

From interface android.os.Parcelable

Fields

public static final Creator<BluetoothGattService> CREATOR

protected List<BluetoothGattCharacteristic> mCharacteristics

List of characteristics included in this service.

protected List<BluetoothGattService> mIncludedServices

List of included services for this service.

Public constructors

BluetoothGattService(UUID uuid, int serviceType)

Create a new BluetoothGattService.

Public methods

boolean addCharacteristic(BluetoothGattCharacteristic characteristic)

Add a characteristic to this service.

boolean addService(BluetoothGattService service)

Add an included service to this service.

BluetoothGattCharacteristic getCharacteristic(UUID uuid)

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

List<BluetoothGattCharacteristic> getCharacteristics()

Returns a list of characteristics included in this service.

List<BluetoothGattService> getIncludedServices()

Get the list of included GATT services for this service.

int getInstanceId()

Returns the instance ID for this service

If a remote device offers multiple services with the same UUID (ex.

int getType()

Get the type of this service (primary/secondary)

UUID getUuid()

Returns the UUID of this service

void writeToParcel(Parcel out, int flags)

Flatten this object in to a Parcel.

Inherited methods

From class java.lang.Object
From interface android.os.Parcelable

Constants

SERVICE_TYPE_PRIMARY

Added in API level 18
int SERVICE_TYPE_PRIMARY

Primary service

Constant Value: 0 (0x00000000)

SERVICE_TYPE_SECONDARY

Added in API level 18
int SERVICE_TYPE_SECONDARY

Secondary service (included by primary services)

Constant Value: 1 (0x00000001)

Fields

CREATOR

Added in API level 24
Creator<BluetoothGattService> CREATOR

mCharacteristics

Added in API level 18
List<BluetoothGattCharacteristic> mCharacteristics

List of characteristics included in this service.

mIncludedServices

Added in API level 18
List<BluetoothGattService> mIncludedServices

List of included services for this service.

Public constructors

BluetoothGattService

Added in API level 18
BluetoothGattService (UUID uuid, 
                int serviceType)

Create a new BluetoothGattService.

Requires BLUETOOTH permission.

Parameters
uuid UUID: The UUID for this service
serviceType int: The type of this service, SERVICE_TYPE_PRIMARY or SERVICE_TYPE_SECONDARY

Public methods

addCharacteristic

Added in API level 18
boolean addCharacteristic (BluetoothGattCharacteristic characteristic)

Add a characteristic to this service.

Requires BLUETOOTH permission.

Parameters
characteristic BluetoothGattCharacteristic: The characteristics to be added
Returns
boolean true, if the characteristic was added to the service

addService

Added in API level 18
boolean addService (BluetoothGattService service)

Add an included service to this service.

Requires BLUETOOTH permission.

Parameters
service BluetoothGattService: The service to be added
Returns
boolean true, if the included service was added to the service

getCharacteristic

Added in API level 18
BluetoothGattCharacteristic getCharacteristic (UUID uuid)

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.

Parameters
uuid UUID
Returns
BluetoothGattCharacteristic GATT characteristic object or null if no characteristic with the given UUID was found.

getCharacteristics

Added in API level 18
List<BluetoothGattCharacteristic> getCharacteristics ()

Returns a list of characteristics included in this service.

Returns
List<BluetoothGattCharacteristic> Characteristics included in this service

getIncludedServices

Added in API level 18
List<BluetoothGattService> getIncludedServices ()

Get the list of included GATT services for this service.

Returns
List<BluetoothGattService> List of included services or empty list if no included services were discovered.

getInstanceId

Added in API level 18
int getInstanceId ()

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.

Returns
int Instance ID of this service

getType

Added in API level 18
int getType ()

Get the type of this service (primary/secondary)

Returns
int

getUuid

Added in API level 18
UUID getUuid ()

Returns the UUID of this service

Returns
UUID UUID of this service

writeToParcel

Added in API level 24
void writeToParcel (Parcel out, 
                int flags)

Flatten this object in to a Parcel.

Parameters
out Parcel: The Parcel in which the object should be written.
flags int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.