Overview

You will find here some code samples to get started with the library usage.
In constrast with the basic usage, these are for an advanced usage, with a service running silently in background. The aim is to have an automated and autonomous application running without any interaction from the user.

Files

For a clean architecture, all library accesses are located under a ble parent.
For simplicity, it is here a subpackage under the app package, but it could also be a module on its own.
app/src/main/java/
└─ my/package/
   ├─ MainApplication.kt
   ├─ MainActivity.kt
   ├─ EventListener.kt
   └─ ble/
      ├─ IStatusCallback.kt
      ├─ IEventListener.kt
      ├─ NotificationHelper.kt
      │
      ├─ Configuration.kt
      ├─ DaemonConfig.kt
      │
      ├─ ScannerManager.kt
      └─ ErrorCodeMessages.kt

Demo

Hereunder, the logcat of a demo session with an implementation closed to the sample code.

19:35:11.174  8890-8890  MainActivity          I  onClickSetUp
19:35:11.180  8890-8890  ScannerManager        D  setUp
19:35:11.186  8890-8890  SDK-ProximityManager  D  Binding to Proximity Service
19:35:11.233  8890-8890  SDK-ProximityService  D  lifecycle onCreate
19:35:11.234  8890-8890  SDK-ProximityService  D  lifecycle onStartCommand, intent: Intent { cmp=fr.maxcom.test.libbeacon/fr.maxcom.beacon.service.ProximityService }
19:35:11.237  8890-8890  SDK-ProximityManager  D  on Proximity Service connected
19:35:11.237  8890-8890  SDK-ProximityService  V  getService
19:35:11.245  8890-8890  SDK-ProximityManager  D  Starting scan
19:35:11.249  8890-8890  SDK-Controller        V  filters: [BluetoothLeScanFilter [mDeviceName=null, mDeviceAddress=null, mUuid=null, mUuidMask=null, mServiceDataUuid=null, mServiceData=null, mServiceDataMask=null,
 mManufacturerId=76, mManufacturerData=[2, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], mManufacturerDataMask=null]]
19:35:11.260  8890-8890  SDK-Scheduler         D  Start request
19:35:11.261  8890-8890  SDK-Controller        D  Starting scan ...
19:35:11.262  8890-8890  BluetoothAdapter      D  STATE_ON
19:35:11.268  8890-8902  BluetoothLeScanner    D  onClientRegistered() - status=0 clientIf=6 mClientIf=0
19:35:11.270  8890-8890  SDK-Controller        D  ... Scan started
19:35:11.270  8890-8890  ScannerManager        D  result onStarted
19:35:11.270  8890-8890  MainActivity          D  onResult: isScanning true
19:35:11.271  8890-8890  SDK-ProximityManager  D  disconnect
19:35:11.373  8890-8890  DaemonConfig          I  onScanStart

19:35:20.853  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-86
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:20.864  8890-8890  DaemonConfig          D  onEntered: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:20.866  8890-8890  DaemonConfig          D  onDiscovered: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-86, 1m=-58, d=19, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:25.844  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-81
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:25.846  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-81, 1m=-58, d=14, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:25.848  8890-8890  DaemonConfig          D  onUpdated: [iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-81, 1m=-58, d=14, Mm=33.33, n=BNBeacon Plus, ex={bp=100}]], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:30.847  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-81
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:30.849  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-81, 1m=-58, d=13, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:35.842  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-85
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:35.843  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-85, 1m=-58, d=14, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:40.842  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-82
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:40.843  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-82, 1m=-58, d=14, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:40.844  8890-8890  DaemonConfig          D  onUpdated: [iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-82, 1m=-58, d=14, Mm=33.33, n=BNBeacon Plus, ex={bp=100}]], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:45.865  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-81
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:45.866  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-81, 1m=-58, d=13, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:50.862  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-85
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:50.864  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-85, 1m=-58, d=13, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:55.849  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-82
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:35:55.850  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-82, 1m=-58, d=14, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:35:55.851  8890-8890  DaemonConfig          D  onUpdated: [iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-82, 1m=-58, d=14, Mm=33.33, n=BNBeacon Plus, ex={bp=100}]], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:36:00.861  8890-8930  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-83
                                                  02 01 06 1B FF 4C 00 02 15 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 21 00 21 C6 64 0E 09 42 4E 42 65 61 63 6F 6E 20 50 6C 75 73 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
19:36:00.862  8890-8890  DaemonConfig          V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-83, 1m=-58, d=13, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}

19:36:29.757  8890-8890  DaemonConfig          D  onLost: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-83, 1m=-58, d=13, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
19:36:29.757  8890-8890  DaemonConfig          D  onExited: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}

19:36:39.431  8890-8890  MainActivity          I  onClickTearDown
19:36:39.431  8890-8890  ScannerManager        D  tearDown
19:36:39.436  8890-8890  SDK-ProximityManager  D  Binding to Proximity Service
19:36:39.464  8890-8890  SDK-ProximityManager  D  on Proximity Service connected
19:36:39.464  8890-8890  SDK-ProximityService  V  getService
19:36:39.465  8890-8890  SDK-ProximityManager  D  Finishing scan
19:36:39.465  8890-8890  SDK-Scheduler         D  Stop request
19:36:39.466  8890-8890  SDK-ProximityManager  D  disconnect
19:36:39.468  8890-8930  SDK-Controller        D  Stopping scan ...
19:36:39.470  8890-8930  BluetoothAdapter      D  STATE_ON
19:36:39.471  8890-8890  SDK-ProximityService  D  lifecycle onDestroy
19:36:39.472  8890-8930  BluetoothAdapter      D  STATE_ON
19:36:39.474  8890-8930  SDK-Controller        D  ... Scan stopped
19:36:39.475  8890-8890  DaemonConfig          I  onScanStop
19:36:39.475  8890-8890  ScannerManager        D  result onStopped
19:36:39.475  8890-8890  MainActivity          D  onResult: isScanning false