public class BluetoothService extends Object
BluetoothService
class represents a remote or a local GATT service.
Remote services may be retrieved by listening to
connection
events
while discovering the services
of a device. The GATT events
related to a remote service may be handled by setting the remote
listener
of the service.
Local services may be retrieved by adding a local
service
to the adapter. The GATT events related to a local service may be handled by
setting the local listener
of the service.
This class provides methods to get the UUID of the service and to get its characteristics.
Modifier and Type | Method and Description |
---|---|
BluetoothCharacteristic |
getCharacteristic(int index)
Returns the characteristic at the given index in this service.
|
int |
getNumCharacteristics()
Returns the number of characteristics in this service.
|
BluetoothUuid |
getUuid()
Returns the UUID of this service.
|
void |
setLocalListener(LocalServiceListener localListener)
Sets the listener which will receive the events related to this local service.
|
void |
setRemoteListener(RemoteServiceListener remoteListener)
Sets the listener which will receive the events related to this remote service.
|
public BluetoothCharacteristic getCharacteristic(int index)
index
- the index of the characteristic.IndexOutOfBoundsException
- if the index is out of range (index < 0 || index >= getNumCharacteristics()
).public int getNumCharacteristics()
public BluetoothUuid getUuid()
public void setLocalListener(LocalServiceListener localListener)
Only one listener may be set at the same time. If the local listener has not been set, the
DefaultLocalServiceListener
will be used to handle the events.
localListener
- the object which will receive the events.IllegalStateException
- if this service is not a local service.public void setRemoteListener(RemoteServiceListener remoteListener)
Only one listener may be set at the same time. If the remote listener has not been set, the
DefaultRemoteServiceListener
will be used to handle the events.
remoteListener
- the object which will receive the events.IllegalStateException
- if this service is not a remote service.