Class BluetoothService
- java.lang.Object
-
- ej.bluetooth.BluetoothService
-
public class BluetoothService extends Object
TheBluetoothServiceclass represents a remote or a local GATT service.Remote services may be retrieved by listening to
connection eventswhilediscovering the servicesof a device. The GATT events related to a remote service may be handled bysetting the remote listenerof the service.Local services may be retrieved by
adding a local serviceto the adapter. The GATT events related to a local service may be handled bysetting the local listenerof the service.This class provides methods to get the UUID of the service and to get its characteristics.
-
-
Constructor Summary
Constructors Constructor Description BluetoothService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BluetoothCharacteristicgetCharacteristic(int index)Returns the characteristic at the given index in this service.intgetNumCharacteristics()Returns the number of characteristics in this service.BluetoothUuidgetUuid()Returns the UUID of this service.voidsetLocalListener(LocalServiceListener localListener)Sets the listener which will receive the events related to this local service.voidsetRemoteListener(RemoteServiceListener remoteListener)Sets the listener which will receive the events related to this remote service.
-
-
-
Method Detail
-
getUuid
public BluetoothUuid getUuid()
Returns the UUID of this service.- Returns:
- the UUID of this service
-
getNumCharacteristics
public int getNumCharacteristics()
Returns the number of characteristics in this service.- Returns:
- the number of characteristics in this service.
-
getCharacteristic
public BluetoothCharacteristic getCharacteristic(int index)
Returns the characteristic at the given index in this service.- Parameters:
index- the index of the characteristic.- Returns:
- the characteristic at the given index.
- Throws:
IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= getNumCharacteristics()).
-
setRemoteListener
public void setRemoteListener(RemoteServiceListener remoteListener)
Sets the listener which will receive the events related to this remote service.Only one listener may be set at the same time. If the remote listener has not been set, the
DefaultRemoteServiceListenerwill be used to handle the events.- Parameters:
remoteListener- the object which will receive the events.- Throws:
IllegalStateException- if this service is not a remote service.
-
setLocalListener
public void setLocalListener(LocalServiceListener localListener)
Sets the listener which will receive the events related to this local service.Only one listener may be set at the same time. If the local listener has not been set, the
DefaultLocalServiceListenerwill be used to handle the events.- Parameters:
localListener- the object which will receive the events.- Throws:
IllegalStateException- if this service is not a local service.
-
-