|
| 1 | +# Android BLE Library |
| 2 | + |
| 3 | +This library has been extracted from [nRF Toolbox](https://github.com/NordicSemiconductor/Android-nRF-Toolbox) |
| 4 | +project. It contains classes useful when doing a connection to a Bluetooth LE device. |
| 5 | + |
| 6 | +### Features |
| 7 | + |
| 8 | +**BleManager** class provides the following features: |
| 9 | + |
| 10 | +1. Connection |
| 11 | +2. Service discovery |
| 12 | +3. Bonding (optional) |
| 13 | +4. Enabling Service Changed indications |
| 14 | +5. Device initialization |
| 15 | +6. Async BLE operations using queue |
| 16 | +7. Reading Battery Level value |
| 17 | +8. Requesting MTU and connection priority |
| 18 | +9. Error handling |
| 19 | +10. Logging (in LogCat and optionally nRF Logger) |
| 20 | + |
| 21 | +It may be used for a single connection (see [nRF Toolbox](https://github.com/NordicSemiconductor/Android-nRF-Toolbox) -> RSC profile) |
| 22 | +or when multiple connections are required (see nRF Toolbox -> Proximity profile), |
| 23 | +from a Service (see nRF Toolbox -> RSC profile), |
| 24 | +ViewModel's repo (see [Architecture Components](https://developer.android.com/topic/libraries/architecture/index.html) and [nRF Blinky](https://github.com/NordicSemiconductor/Android-nRF-Blinky)), |
| 25 | +or as a singleton (not recommended, see nRF Toolbox -> HRM). |
| 26 | + |
| 27 | +**BleManager** exposes a high level API instead of low level BLE operations. |
| 28 | +If autoConnect option is to be used, the manager also handles initial connection (with autoConnect = false), |
| 29 | +which is much faster, and then reconnects in case of link loss with this parameter set to true. |
| 30 | +Just return *true* from `shouldAutoConnect()` method in your manager. |
| 31 | + |
| 32 | +### How to include it in your project |
| 33 | + |
| 34 | +Clone this project and add *ble* module as a dependency to your project: |
| 35 | + |
| 36 | +1. In *settings.gradle* file add the following lines: |
| 37 | +```groovy |
| 38 | +include ':ble' |
| 39 | +project(':ble').projectDir = file('../Android-BLE-Library/ble') |
| 40 | +``` |
| 41 | +2. In *app/build.gradle* file add `implementation project(':ble')` inside dependencies. |
| 42 | +3. Sync project and build it |
| 43 | + |
| 44 | +See example projects listed below. |
| 45 | + |
| 46 | +### How to use it |
| 47 | + |
| 48 | +1. Define your device API by extending BleManagerCallbacks: [example](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/master/app/src/main/java/no/nordicsemi/android/blinky/profile/BlinkyManagerCallbacks.java) |
| 49 | +2. Extend BleManager class and implement required methods: [example](https://github.com/NordicSemiconductor/Android-nRF-Blinky/blob/master/app/src/main/java/no/nordicsemi/android/blinky/profile/BlinkyManager.java) |
| 50 | + |
| 51 | +### Example |
| 52 | + |
| 53 | +Find the simple example here [Android nRF Blinky](https://github.com/NordicSemiconductor/Android-nRF-Blinky). |
| 54 | + |
| 55 | +For an example how to use it from an Activity or a Service, check the base Activity and Service classes in [nRF Toolbox](https://github.com/NordicSemiconductor/Android-nRF-Toolbox/tree/master/app/src/main/java/no/nordicsemi/android/nrftoolbox/profile). |
0 commit comments