This is an BLE extension library that wraps Android's BluetootGattService into something easier to use.
The problem with Android's bluetooth:
- simply calling
BluetoothGattCharacteristic.setNotificationEnabled()
is not enough, you need to write theBluetoothGattDescriptor
and enable the notifications. - each operation (
readCharacteristic()
,writeCharacteristic()
,readDescriptor()
,writeDescriptor()
) has to wait till previous operation finish before you can issue the next one. - the profile / service / characteristic / descriptor support in Android BLE stack is pretty limitted, this library provides an object oriented way to manipulate them.
Register the listeners to BluetoothDevice
for onConnectionStateChanged()
and onServiceDiscovered()
, and register listeners to BluetoothGattService
for specific characteristic update.
Extends BluetoothGattService
:
- create an
UUID_SERVICE
matching your service UUID - make listeners and dispatchers for READ and NOTIFY events...
- add
@Keep
to sub-classes ofBluetoothGattService
and it's correspondingUUID_SERVICE
so proguard don't strip them.
That's it!
git submodule add https://github.com/Palatis/android-ble.git
to add this repo to your project- modify
settings.gradle
to include the project with correct path to the library module directoryinclude ':app' // your app include ':android-ble' // this repo project(':android-ble').projectDir = file('./android-ble/ble') // path to library module
- add the library module to your app's dependency by modifying
app/build.gradle
... dependencies { ... compile project(path: ':android-ble') ... } ...