Android BLE Made Easy
An easy to use, kotlin friendly BLE library for Android.
Installing
- Step 1. Add the JitPack repository to your project gradle file
- Step 2. Add the implementation dependency to your app gradle file
- Step 3. Gradle sync and you're ready to go!
Core features
Lifecycle
The library accepts being used both in an Activity and a Fragment!
Automatic handle permissions
The library requests the permissions for you.
Asynchronous:
Coroutines:
Automatic turn on the Bluetooth adapter
The library requests the Bluetooth hardware to be activated whenever it is off.
Asynchronous:
Coroutines:
Automatic turn on Location services
The library requests Location services to be activated whenever it is off.
Asynchronous:
Coroutines:
Asynchronous and Coroutines
You can both use the library with callbacks and with coroutines suspended functions
The callback functions having the 'async' suffix.
And requiring a HOF callback as a parameter .
Handling the bluetooth connections with graceful connection shutdown, in another words, waits for current running operations (Read and Write) to be finished before closing the connection
JetPack Contracts Ready!
The library uses the new JetPack contracts API to automatically handle permissions and adapter activation for you.
Compatible with older API levels
Theoretically compatible all the way down to API 18, but made targeting API 21+.
Well documented!
All the functions and variables you're gonna be using are very well documented with KotlinDOC.
So you can get autocompletion information on Android Studio.
But if you want to take a look without installing it... You can take a look on the dokka generated documentation
Both low level bytes and String conversion
The library gives you the option to receive and send raw Bytes if you want.
But also you can let it encode and decode your strings automatically.
Automatically handles the pain of Known issues
Take for instance Issue 183108 where Lollipop devices will not work properly without a workaround to handle the connection.
Or the well-known BLE 133 error! The nightmare of everyone that already worked with BLE on Android, this library has a compilation of techniques being used to get around it
Usage
After instantiating the BLE
class...
Fast scan for a specific device
If you already know the device you wanna connect to, you could use this:
Asynchronous:
Coroutines:
Scanning BLE devices
Asynchronous:
Coroutines:
Or you could use the scan method without any timeout, only stopping it manually
Manually connecting to a discovered device
After a successful scan, you'll have your Bluetooth device, now it is time to connect with it!
Made With <3 by Leandro Quevedo