to top
Android APIs
public class

BluetoothGattService

extends Object
java.lang.Object
   ↳ android.bluetooth.BluetoothGattService

Class Overview

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)
Fields
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
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int SERVICE_TYPE_PRIMARY

Added in API level 18

Primary service

Constant Value: 0 (0x00000000)

public static final int SERVICE_TYPE_SECONDARY

Added in API level 18

Secondary service (included by primary services)

Constant Value: 1 (0x00000001)

Fields

protected List<BluetoothGattCharacteristic> mCharacteristics

Added in API level 18

List of characteristics included in this service.

protected List<BluetoothGattService> mIncludedServices

Added in API level 18

List of included services for this service.

Public Constructors

public BluetoothGattService (UUID uuid, int serviceType)

Added in API level 18

Create a new BluetoothGattService.

Requires BLUETOOTH permission.

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

Public Methods

public boolean addCharacteristic (BluetoothGattCharacteristic characteristic)

Added in API level 18

Add a characteristic to this service.

Requires BLUETOOTH permission.

Parameters
characteristic The characteristics to be added
Returns
  • true, if the characteristic was added to the service

public boolean addService (BluetoothGattService service)

Added in API level 18

Add an included service to this service.

Requires BLUETOOTH permission.

Parameters
service The service to be added
Returns
  • true, if the included service was added to the service

public BluetoothGattCharacteristic getCharacteristic (UUID uuid)

Added in API level 18

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.

Returns
  • GATT characteristic object or null if no characteristic with the given UUID was found.

public List<BluetoothGattCharacteristic> getCharacteristics ()

Added in API level 18

Returns a list of characteristics included in this service.

Returns
  • Characteristics included in this service

public List<BluetoothGattService> getIncludedServices ()

Added in API level 18

Get the list of included GATT services for this service.

Returns
  • List of included services or empty list if no included services were discovered.

public int getInstanceId ()

Added in API level 18

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
  • Instance ID of this service

public int getType ()

Added in API level 18

Get the type of this service (primary/secondary)

public UUID getUuid ()

Added in API level 18

Returns the UUID of this service

Returns
  • UUID of this service