public class BluetoothService
extends java.lang.Object
BluetoothService
class represents a remote or a local GATT service.
Remote services may be retrieved from a Bluetooth device by discovering its
services
. The GATT events related to the remote service may be handled by setting the
client callbacks
.
Local services may be created by using the class constructor
and
added
to an adapter. The GATT events related to the local service may be handled
by setting the server callbacks
.
This class provides methods to get information on the service. It also allows to add characteristics and included services to a local service.
Modifier and Type | Class and Description |
---|---|
static class |
BluetoothService.Type
The
Type class enumerates the values for service types. |
Constructor and Description |
---|
BluetoothService(BluetoothUuid uuid,
BluetoothService.Type type)
Creates a local service with the given UUID and type.
|
Modifier and Type | Method and Description |
---|---|
void |
addCharacteristic(BluetoothCharacteristic characteristic)
Adds a characteristic to this service.
|
void |
addIncludedService(BluetoothService service)
Adds a service to include in this service.
|
BluetoothCharacteristic |
findCharacteristic(BluetoothUuid characteristicUuid)
Finds the characteristic of this service which matches the given UUID.
|
BluetoothService |
findIncludedService(BluetoothUuid serviceUuid)
Finds the service included by this service which matches the given UUID.
|
BluetoothCharacteristic[] |
getCharacteristics()
Returns the list of characteristics of this service.
|
BluetoothService[] |
getIncludedServices()
Returns the list of services included in this service.
|
BluetoothService.Type |
getType()
Returns the type of this service.
|
BluetoothUuid |
getUuid()
Returns the UUID of this service.
|
void |
setClientCallbacks(ClientCallbacks clientCallbacks)
Sets the object which will receive the client events related to this service.
|
void |
setServerCallbacks(ServerCallbacks serverCallbacks)
Sets the object which will receive the server events related to this service.
|
public BluetoothService(BluetoothUuid uuid, BluetoothService.Type type)
This service may then be added
to an adapter.
The GATT events related to this service may be handled by setting the server
callbacks
.
uuid
- the service UUID.type
- the service type (primary or secondary).public void addCharacteristic(BluetoothCharacteristic characteristic)
characteristic
- the characteristic to add.java.lang.IllegalStateException
- if this service belongs to a remote device.java.lang.IllegalStateException
- if this service has already been added to an adapter.java.lang.IllegalStateException
- if the characteristic has already been added to a service.public void addIncludedService(BluetoothService service)
service
- the service to include.java.lang.IllegalStateException
- if this service belongs to a remote device.java.lang.IllegalStateException
- if this service has already been added to an adapter.public BluetoothUuid getUuid()
public BluetoothService.Type getType()
public BluetoothCharacteristic[] getCharacteristics()
public BluetoothService[] getIncludedServices()
public BluetoothCharacteristic findCharacteristic(BluetoothUuid characteristicUuid)
If multiple characteristics have the same UUID, any of them may be returned.
characteristicUuid
- the UUID of the characteristic to find.public BluetoothService findIncludedService(BluetoothUuid serviceUuid)
If multiple included services have the same UUID, any of them may be returned.
serviceUuid
- the UUID of the service to find.public void setClientCallbacks(ClientCallbacks clientCallbacks)
clientCallbacks
- the object which will receive the client events.java.lang.IllegalStateException
- if this service does not belong to a remote device.public void setServerCallbacks(ServerCallbacks serverCallbacks)
serverCallbacks
- the object which will receive the server events.java.lang.IllegalStateException
- if this service belongs to a remote device.