Skip to main content

BleService

Class: BleService(context: Context)

Serves as the main entry point for interacting with the Bluetooth Low Energy (BLE) SDK.

Before using any BLE functionality, you must initialize the SDK by calling BleService.configure(). All methods are on the companion object.

Static Methods (Companion Object)​

configure()​

fun configure(context: Context): BleService

Configures the BleService. This function should be called first, once.

Every call creates a new service: a second call drops the terminals created so far, and getTerminal() then returns new BleTerminal instances while the earlier ones may still be connected. Guard it with isConfigured() or call it from Application.onCreate().

Parameters:

  • context - The application context. It is kept for the lifetime of the SDK, so do not pass an Activity.

getTerminal(terminalId: String)​

fun getTerminal(terminalId: String): BleTerminal

Get an instance of BleTerminal associated with the given terminal ID. The same instance is returned on every call.

Parameters:

  • terminalId - The unique identifier for the desired BLE terminal: the Bluetooth name it advertises. It is compared exactly with the advertised name: case-sensitive, not trimmed.

Returns: BleTerminal instance

Throws: IllegalArgumentException if configure() has not been called.

isConfigured()​

fun isConfigured(): Boolean

Checks whether configure() has been called.

Returns: true once the service is configured, false otherwise

clear()​

fun clear()

Clears the configured instance and its terminals. Call configure() again before further use. It does not disconnect the terminals: call BleTerminal.disconnect() on a connected terminal first.

See Also​