Skip to content

mohamed-elbehiry/CoBle

Repository files navigation

CoBle (Coroutines BLE) (under developement...)


License API


Android library that solves some of Android's Bluetooth Low Energy problems I had.

  • This library is still in progress & on testing...
  • It solves the common problems one regularly have with BLE on Android, like race conditions, queueing commands, and blocking of binder threads.

Usage

SDK Init

CoBle.init(config)
  • Configuration
val config = config(context = applicationContext) {} 
  • an optional way to inject some feature for example BluetoothUsabilityFeature which used to handle Bluetooth Permissions checks & Location service.
val config = config(context = applicationContext) {
  addFeature(BluetoothUsabilityFeature.Instance)
} 

Scanner

val scanner: BluetoothScanner
scanner.startScanning()
scanner.stopScanning()
  • Scanning with configured configuration
val scanningConfiguration = ScanningConfig.Builder()
        .setScanSetting(ScanSettings.Builder().build())
        .setNamePatterns(listOf(Pattern.compile("")))
        .setScanFilters(listOf(ScanFilter.Builder().setDeviceName("").build()))
        .build()
        
scanner.startScanning(scanningConfiguration)

Connector

val connector: BluetoothConnector
connector.connect(bluetoothDevice)

Interaction

val connector: BluetoothConnector
connector.connect(...)
connector.getServices()
connector.getService(...)
connector.discoverServices()
connector.readCharacteristic(...)
connector.writeCharacteristic(...)
connector.writeDescriptor(...)
connector.readDescriptor(...)
connector.setPreferredPhy(...)