Overview

You will find here some code samples to get started with the library usage.
These are for a basic usage, with a foreground activity and a user in control.

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
   └─ ble/
      ├─ IStatusCallback.kt
      │
      ├─ Configuration.kt
      ├─ UserConfig.kt
      │
      ├─ ScannerManager.kt
      └─ ErrorCodeMessages.kt

Demo

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

The related logcat:

18:14:05.829  1406-1406  MainActivity          D  lifecycle onCreate

18:14:10.840  1406-1406  MainActivity          D  onClickSetUp
18:14:10.843  1406-1406  ScannerManager        D  setUp
18:14:10.846  1406-1406  SDK-ProximityManager  D  Binding to Proximity Service
18:14:10.861  1406-1406  SDK-ProximityService  D  lifecycle onCreate
18:14:10.862  1406-1406  SDK-ProximityService  D  lifecycle onStartCommand, intent: Intent { cmp=fr.maxcom.test.libbeacon/fr.maxcom.beacon.service.ProximityService }
18:14:10.864  1406-1406  SDK-ProximityManager  D  on Proximity Service connected
18:14:10.864  1406-1406  SDK-ProximityService  V  getService
18:14:10.864  1406-1406  SDK-ProximityManager  D  Starting scan
18:14:10.865  1406-1406  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]]
18:14:10.870  1406-1406  SDK-Scheduler         D  Start request
18:14:10.871  1406-1406  SDK-Controller        D  Starting scan ...
18:14:10.872  1406-1406  BluetoothAdapter      D  STATE_ON
18:14:10.878  1406-1427  BluetoothLeScanner    D  onClientRegistered() - status=0 clientIf=6 mClientIf=0
18:14:10.882  1406-1406  SDK-Controller        D  ... Scan started
18:14:10.882  1406-1406  ScannerManager        D  result onStarted
18:14:10.882  1406-1406  MainActivity          D  onResult: isScanning true
18:14:10.883  1406-1406  SDK-ProximityManager  D  disconnect
18:14:10.932  1406-1406  UserConfig            D  onScanStart

18:14:19.051  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-76
                                                  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
18:14:19.053  1406-1406  UserConfig            D  onEntered: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:19.053  1406-1406  UserConfig            D  onDiscovered: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-76, 1m=-58, d=7, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:24.043  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-69
                                                  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
18:14:24.045  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-69, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:24.050  1406-1406  UserConfig            D  onUpdated: [iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-69, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}]], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:29.043  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-71
                                                  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
18:14:29.044  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-71, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:34.036  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-76
                                                  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
18:14:34.037  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-76, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:39.051  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-68
                                                  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
18:14:39.053  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-68, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:39.054  1406-1406  UserConfig            D  onUpdated: [iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-68, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}]], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:44.057  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-70
                                                  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
18:14:44.058  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-70, 1m=-58, d=4, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:49.057  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-76
                                                  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
18:14:49.058  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-76, 1m=-58, d=7, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:59.073  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-71
                                                  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
18:14:59.075  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-71, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:14:59.076  1406-1406  UserConfig            D  onUpdated: [iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-71, 1m=-58, d=5, Mm=33.33, n=BNBeacon Plus, ex={bp=100}]], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:15:04.066  1406-9967  SDK-MyScanCallback    V  BLE frame, ad=FF:7D:9D:CA:C0:A3, r=-76
                                                  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
18:15:04.069  1406-1406  UserConfig            V  onKnown: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-76, 1m=-58, d=6, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}

18:15:32.755  1406-1406  UserConfig            D  onLost: iBeacon [ad=FF:7D:9D:CA:C0:A3, rs=-76, 1m=-58, d=6, Mm=33.33, n=BNBeacon Plus, ex={bp=100}], region: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}
18:15:32.757  1406-1406  UserConfig            D  onExited: {BNB Plus, 00000000-0000-0000-0000-000000000000, ANY_MAJOR, ANY_MINOR}

18:15:43.914  1406-1406  MainActivity          D  onClickTearDown
18:15:43.914  1406-1406  ScannerManager        D  tearDown
18:15:43.918  1406-1406  SDK-ProximityManager  D  Binding to Proximity Service
18:15:43.933  1406-1406  SDK-ProximityManager  D  on Proximity Service connected
18:15:43.933  1406-1406  SDK-ProximityService  V  getService
18:15:43.933  1406-1406  SDK-ProximityManager  D  Finishing scan
18:15:43.933  1406-1406  SDK-Scheduler         D  Stop request
18:15:43.933  1406-1406  SDK-ProximityManager  D  disconnect
18:15:43.935  1406-9967  SDK-Controller        D  Stopping scan ...
18:15:43.936  1406-9967  BluetoothAdapter      D  STATE_ON
18:15:43.936  1406-1406  SDK-ProximityService  D  lifecycle onDestroy
18:15:43.938  1406-9967  BluetoothAdapter      D  STATE_ON
18:15:43.941  1406-9967  SDK-Controller        D  ... Scan stopped
18:15:43.942  1406-1406  UserConfig            D  onScanStop
18:15:43.978  1406-1406  ScannerManager        D  result onStopped
18:15:43.978  1406-1406  MainActivity          D  onResult: isScanning false