This library has been extracted from nRF Toolbox project. It contains classes useful when doing a connection to a Bluetooth LE device.
BleManager class provides the following features:
- Connection
- Service discovery
- Bonding (optional)
- Enabling Service Changed indications
- Device initialization
- Async BLE operations using queue
- Reading Battery Level value
- Requesting MTU and connection priority
- Error handling
- Logging (in nRF Logger)
The library does not provide support for scanning for Bluetooth LE devices. For scanning, we recommend using Android Scanner Compat Library which brings almost all recent features, introduced in Lollipop and later, to the older platforms.
The library may be found on jcenter and Maven Central repository. Add it to your project by adding the following dependency:
implementation 'no.nordicsemi.android:ble:1.2.0'
Clone this project and add ble module as a dependency to your project:
- In settings.gradle file add the following lines:
include ':ble'
project(':ble').projectDir = file('../Android-BLE-Library/ble')
- In app/build.gradle file add
implementation project(':ble')
inside dependencies. - Sync project and build it.
See example projects listed below.
Some things has changed before the lib graduated to 1.x. Those are:
- Request class has been extracted to a standalone class, importing this class may be required.
- Current MTU is now available in the BleManager. Use
getMtu()
to get the value. Request change usingrequestMtu(int)
as before.
Find the simple example here Android nRF Blinky.
For an example how to use it from an Activity or a Service, check the base Activity and Service classes in nRF Toolbox.
- Define your device API by extending
BleManagerCallbacks
: example - Extend
BleManager
class and implement required methods: example
For examples of BLE Library v1.x please use older branches of above projects.
Please, check version 2.0 on master branch. Version 2 adds more features (for example synchronous requests, and more), is "almost" backwards compatible (a lot of old API has been deprecated).