Package ej.bluetooth.listeners

## Interface ConnectionListener

- All Known Implementing Classes:
    `DefaultConnectionListener`

      public interface ConnectionListener

  The `ConnectionListener` interface provides callbacks related to advertising, scanning and connections.

  Before `starting to advertise` or before `starting to scan`, the application may `set the connection listener` of the adapter in order to be notified of the events related to this adapter.

  This library provides a default implementation of this interface: `DefaultConnectionListener`.

- - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `onAdvertisementCompleted()` | Called when an ongoing advertisement is completed.
    `void` | `onConnected​(BluetoothConnection connection)` | Called when a connection attempt is successful or when a remote device connects to the adapter.
    `void` | `onConnectFailed​(BluetoothAddress address)` | Called when a connection attempt fails.
    `void` | `onDisconnected​(BluetoothConnection connection)` | Called when the connection with a device is closed.
    `void` | `onDiscoveryCompleted​(BluetoothConnection connection)` | Called when a service discovery is completed.
    `void` | `onDiscoveryResult​(BluetoothConnection connection, BluetoothService service)` | Called when a service provided by a device has been discovered.
    `void` | `onPairCompleted​(BluetoothConnection connection, boolean success)` | Called when the pairing procedure with a device is completed.
    `void` | `onPairRequest​(BluetoothConnection connection)` | Called when a pairing request from a device is received.
    `void` | `onPasskeyGenerated​(BluetoothConnection connection, int passkey)` | Called when a passkey is generated to be displayed to the user.
    `void` | `onPasskeyRequest​(BluetoothConnection connection)` | Called when a passkey request from a device is received.
    `void` | `onScanCompleted()` | Called when an ongoing scan is completed.
    `void` | `onScanResult​(BluetoothAddress address, byte[] advertisementData, int rssi)` | Called when a advertisement or a scan response is received.

- - ### Method Detail

    - #### onAdvertisementCompleted

          void onAdvertisementCompleted()

      Called when an ongoing advertisement is completed.
      See Also:
        `BluetoothAdapter.startAdvertising(byte[])`, `BluetoothAdapter.stopAdvertising()`

    - #### onScanCompleted

          void onScanCompleted()

      Called when an ongoing scan is completed.
      See Also:
        `BluetoothAdapter.startScanning(ej.bluetooth.BluetoothScanFilter)`, `BluetoothAdapter.stopScanning()`

    - #### onScanResult

          void onScanResult​(BluetoothAddress address,
                            byte[] advertisementData,
                            int rssi)

      Called when a advertisement or a scan response is received.
      Parameters:
        `address` - the address of the device which has sent the advertisement.
        `advertisementData` - the advertisement data.
        `rssi` - the RSSI measurement.
      See Also:
        `BluetoothAdapter.startScanning(ej.bluetooth.BluetoothScanFilter)`, `BluetoothAdapter.stopScanning()`

    - #### onConnectFailed

          void onConnectFailed​(BluetoothAddress address)

      Called when a connection attempt fails.
      Parameters:
        `address` - the address of the device to which the connection has failed.
      See Also:
        `BluetoothAdapter.connect(BluetoothAddress)`

    - #### onConnected

          void onConnected​(BluetoothConnection connection)

      Called when a connection attempt is successful or when a remote device connects to the adapter.
      Parameters:
        `connection` - the connection which was established.
      See Also:
        `BluetoothAdapter.connect(BluetoothAddress)`, `BluetoothAdapter.startAdvertising(byte[])`

    - #### onDisconnected

          void onDisconnected​(BluetoothConnection connection)

      Called when the connection with a device is closed.
      Parameters:
        `connection` - the connection which was closed.
      See Also:
        `BluetoothConnection.disconnect()`

    - #### onPairRequest

          void onPairRequest​(BluetoothConnection connection)

      Called when a pairing request from a device is received.
      Parameters:
        `connection` - the connection with the device from which the pairing request was received.
      See Also:
        `BluetoothConnection.sendPairResponse(boolean)`

    - #### onPairCompleted

          void onPairCompleted​(BluetoothConnection connection,
                               boolean success)

      Called when the pairing procedure with a device is completed.
      Parameters:
        `connection` - the connection with the device with which the pairing procedure was completed.
        `success` - true if the pairing procedure was successful, false otherwise.
      See Also:
        `BluetoothConnection.sendPairRequest()`, `BluetoothConnection.sendPairResponse(boolean)`

    - #### onPasskeyRequest

          void onPasskeyRequest​(BluetoothConnection connection)

      Called when a passkey request from a device is received.
      Parameters:
        `connection` - the connection with the device from which the passkey request was received.
      See Also:
        `BluetoothConnection.sendPasskeyResponse(boolean, int)`

    - #### onPasskeyGenerated

          void onPasskeyGenerated​(BluetoothConnection connection,
                                  int passkey)

      Called when a passkey is generated to be displayed to the user.
      Parameters:
        `connection` - the connection with the device to which the passkey request was sent.
        `passkey` - the passkey which was generated.
      See Also:
        `BluetoothConnection.sendPasskeyResponse(boolean, int)`

    - #### onDiscoveryResult

          void onDiscoveryResult​(BluetoothConnection connection,
                                 BluetoothService service)

      Called when a service provided by a device has been discovered.
      Parameters:
        `connection` - the connection with the device which provides the service.
        `service` - the service which has been discovered.
      See Also:
        `BluetoothConnection.discoverServices()`, `BluetoothConnection.discoverService(ej.bluetooth.BluetoothUuid)`

    - #### onDiscoveryCompleted

          void onDiscoveryCompleted​(BluetoothConnection connection)

      Called when a service discovery is completed.
      Parameters:
        `connection` - the connection with the device with which the discovery was initiated.
      See Also:
        `BluetoothConnection.discoverServices()`, `BluetoothConnection.discoverService(ej.bluetooth.BluetoothUuid)`