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 instanceauthKey- 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:
strength- The new BleSignalStrength.rssiValue- Raw RSSI value
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:
action- The BleAction that was executed.
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:
terminal- The BleTerminal that was connected.
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:
terminal- The BleTerminal that was disconnected.
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 grantedBleError.BluetoothDisabled- Bluetooth was turned off while the SDK was in useBleError.BluetoothUnsupported- The phone has no Bluetooth Low EnergyBleError.SaveAuthKeyFailed- The key could not be savedBleError.KeyNotFound- Authentication key not foundBleError.KeyInvalid- Authentication key is not 64 hexadecimal charactersBleError.TerminalNotFound- Terminal not in range or not discoverableBleError.NotConnected- Not connected to terminalBleError.LocationUnauthorized- Location permission not granted, or location services offBleError.GattError- GATT connection errorBleError.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
- BleTerminal - For terminal operations
- BleService - For SDK initialization
- Error Handling - For detailed error information