BluetoothGattService  |  API reference  |  Android Developers


public class BluetoothGattService
extends Object implements Parcelable



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

int CONTENTS_FILE_DESCRIPTOR

Descriptor bit used with describeContents(): indicates that the Parcelable object's flattened representation includes a file descriptor.

int PARCELABLE_WRITE_RETURN_VALUE

Flag for use with writeToParcel(Parcel, int): the object being written is a return value, that is the result of a function such as "Parcelable someFunction()", "void someFunction(out Parcelable)", or "void someFunction(inout 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.

int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

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

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(long timeoutMillis, int nanos)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait(long timeoutMillis)

Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

final void wait()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

From interface android.os.Parcelable

abstract int describeContents()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

abstract void writeToParcel(Parcel dest, int flags)

Flatten this object in to a Parcel.

Constants

SERVICE_TYPE_PRIMARY

public static final int SERVICE_TYPE_PRIMARY

Primary service

Constant Value: 0 (0x00000000)

SERVICE_TYPE_SECONDARY

public static final int SERVICE_TYPE_SECONDARY

Secondary service (included by primary services)

Constant Value: 1 (0x00000001)

Fields

Public constructors

Public methods

addCharacteristic

public boolean addCharacteristic (BluetoothGattCharacteristic characteristic)

Add a characteristic to this service.

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

addService

public boolean addService (BluetoothGattService service)

Add an included service to this service.

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

describeContents

public int describeContents ()

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel,int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Returns
int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
Value is either 0 or

getCharacteristic

public 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.

getIncludedServices

public 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

public 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 distinguish services.

Returns
int Instance ID of this service

getType

public int getType ()

Get the type of this service (primary/secondary)

Returns
int

getUuid

public UUID getUuid ()

Returns the UUID of this service

Returns
UUID UUID of this service