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 theBluetoothGattDescriptorand 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_SERVICEmatching your service UUID - make listeners and dispatchers for READ and NOTIFY events...
- add
@Keepto sub-classes ofBluetoothGattServiceand it's correspondingUUID_SERVICEso proguard don't strip them.
That's it!
git submodule add https://github.com/Palatis/android-ble.gitto add this repo to your project- modify
settings.gradleto 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') ... } ...