Connection
Bluetooth Low Energy (BLE) defines a couple of roles that BLE devices can operate in. Two of these roles are a central role and a peripheral role. A device that is operating in the central role initiates establishment of a physical connection. On the contrary, a device that is operating in the peripheral role accepts a connection request from another device.
Android app can take the central role by using BleConnection
API.
Quick Start
1. Initialize BLESS
Initialize BLESS library in your Android app to use its connection API.
Bless.initialize(applicationContext)
2. Instantiate BleConnection
Instantiate BleConnection
by calling appropriate method in Bless
object.
val remoteDeviceAddress = "00:11:22:33:AA:BB"
val connection = Bless.createBleConnection(remoteDeviceAddress)
3. Register listener
Register a listener that inherits BleConnection.Listener
connection.registerListener(MyListener())
4. Connect
Now you can connect and listen for events
connection.connect()
Reconnectable connection
Create a BleConnection
with a reconnection logic.
val connection = Bless.createBleConnection(
remoteDeviceAddress,
arrayOf(1, 3, 5),
TimeUnit.SECONDS
)
When a BLE connection drops, the reconnection logic will try to reconnect 3 times with 1, 3, and 5 seconds delay between attempts.