Package ej.bluetooth

## Class BluetoothService

- java.lang.Object
- - ej.bluetooth.BluetoothService

-     public class BluetoothService
      extends Object

  The `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.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `BluetoothService()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | 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.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### BluetoothService

          public BluetoothService()

  - ### 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 `DefaultRemoteServiceListener` will 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 `DefaultLocalServiceListener` will 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.