Skip to main content

BleListener

Interface: BleListener

Represents a listener for events and state changes related to a BleTerminal. This interface provides methods that will be invoked by the BleTerminal to notify the listener about connection status, data received, errors, etc.

Assign it with BleTerminal.bleListener. A terminal has a single listener: assigning another one replaces it. Most callbacks are posted to the main thread; onSaveAuthKeySuccess, onRemoveAuthKeySuccess and a few errors are called synchronously, before the method that triggers them returns (see Threading). The Integration guide lists when each callback is called, with the line the demo app writes for it.

Methods​

onError(bleError: BleError)​

abstract fun onError(bleError: BleError)

Called when an error occurs during a BleTerminal operation. A BleError.CtgError does not close the connection. Other errors that end a connection or a connection attempt, such as BleError.GattError, are reported after onTerminalDisconnected.

Parameters:

  • bleError - The BleError that occurred.

onReconnect()​

abstract fun onReconnect()

Called each time the SDK retries after the Bluetooth GATT layer returned GATT_ERROR or GATT_FAILURE. After 3 attempts the SDK gives up and reports BleError.GattError through onError.

onRemoveAuthKeySuccess()​

abstract fun onRemoveAuthKeySuccess()

Called when the authentication key is successfully removed.

onSaveAuthKeySuccess(terminal: BleTerminal, authKey: String)​

abstract fun onSaveAuthKeySuccess(terminal: BleTerminal, authKey: String)

Called when the authentication key is successfully saved.

Parameters:

  • terminal - The BleTerminal instance
  • authKey - The authentication key that was saved.

onSignalStrength(strength: BleSignalStrength, rssiValue: Int)​

abstract fun onSignalStrength(strength: BleSignalStrength, rssiValue: Int)

Called with the signal strength of the connected terminal, about every 7 seconds. It can also be called during a connection attempt, before onTerminalConnected.

Parameters:

onTerminalCommandResult(action: BleAction)​

abstract fun onTerminalCommandResult(action: BleAction)

Called when a terminal command returns a result: LOCK, UNLOCK, UNLOCK_NOKEYFOB, HEADLIGHT, HORN or GET_LOCK_STATE. For LOCK and UNLOCK it is called once the SDK has read the new lock state, so BleTerminal.getLockState() is up to date inside the callback.

It is also called once with GET_LOCK_STATE right after onTerminalConnected, without your app sending that action: the SDK reads the lock state itself after connecting.

Parameters:

onTerminalConnected(terminal: BleTerminal)​

abstract fun onTerminalConnected(terminal: BleTerminal)

Called when the BleTerminal successfully connects to a device and the terminal has accepted the key. Actions can be sent from now on. BleTerminal.getLockState() is UNKNOWN until the first onTerminalCommandResult(GET_LOCK_STATE).

Parameters:

onTerminalDisconnected(terminal: BleTerminal)​

abstract fun onTerminalDisconnected(terminal: BleTerminal)

Called when the terminal is disconnected, whether by BleTerminal.disconnect() or because the Bluetooth link dropped (terminal out of range or powered off, Bluetooth turned off, or an error that ended the connection). BleTerminal.disconnect() always triggers it, even when nothing was connected; from 3.0.4 once per call.

Parameters:

onTerminalDidGetVehicleStats(command: Byte, getVehicleStats: GetVehicleStats)​

abstract fun onTerminalDidGetVehicleStats(command: Byte, getVehicleStats: GetVehicleStats)

Called with the result of BleAction.VEHICLE_GET_CONFIG.

Parameters:

  • command - The raw terminal command byte the response belongs to.
  • getVehicleStats - The parsed GetVehicleStats.

onTerminalDidGetVehicleStatus(command: Byte, getVehicleStatus: GetVehicleStatus)​

abstract fun onTerminalDidGetVehicleStatus(command: Byte, getVehicleStatus: GetVehicleStatus)

Called with the result of BleAction.VEHICLE_GET_STATUS.

Parameters:

  • command - The raw terminal command byte the response belongs to.
  • getVehicleStatus - The parsed GetVehicleStatus.

Error Types​

The BleError types onError can receive:

  • BleError.BluetoothUnauthorized - Bluetooth permission not granted
  • BleError.BluetoothDisabled - Bluetooth was turned off while the SDK was in use
  • BleError.BluetoothUnsupported - The phone has no Bluetooth Low Energy
  • BleError.SaveAuthKeyFailed - The key could not be saved
  • BleError.KeyNotFound - Authentication key not found
  • BleError.KeyInvalid - Authentication key is not 64 hexadecimal characters
  • BleError.TerminalNotFound - Terminal not in range or not discoverable
  • BleError.NotConnected - Not connected to terminal
  • BleError.LocationUnauthorized - Location permission not granted, or location services off
  • BleError.GattError - GATT connection error
  • BleError.CtgError - The terminal refused a command or the key, or the SDK gave up on a command

See Error codes in the integration guide for what to do with each.

See Also​