Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sorz/gattkt
Android library that convert `BluetoothGattCallback` to ergonomic Kotlin coroutines API.
https://github.com/sorz/gattkt
android-bluetooth android-library
Last synced: about 2 months ago
JSON representation
Android library that convert `BluetoothGattCallback` to ergonomic Kotlin coroutines API.
- Host: GitHub
- URL: https://github.com/sorz/gattkt
- Owner: sorz
- License: mit
- Created: 2020-04-03T09:25:53.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-05T09:33:12.000Z (over 4 years ago)
- Last Synced: 2023-10-20T23:12:05.472Z (about 1 year ago)
- Topics: android-bluetooth, android-library
- Language: Kotlin
- Size: 75.2 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# GattKt
Android library that convert `BluetoothGattCallback` to ergonomic Kotlin
coroutines API.See also [sorz/blescanner](https://github.com/sorz/blescanner) for library
that scan BLE device with Kotlin coroutines.Current support:
- [x] Connect to GATT server and discovery GATT services
- [x] Write an characteristic
- [x] Enable/disable notification/indication (with necessary descriptor set)
- [x] Read notification/indication valuePR is welcome if you need more functions.
## Install
- Add [JitPack](https://jitpack.io/) to your build file.
- Add `implementation 'com.github.sorz:gattkt:{VERSION}`## Example
```kotlin
suspend fun handleAwesomeDevice(context: Context, device: BluetoothDevice) {
val gattIo = device.connectGattIo(context)
val char = gattIo.requireCharacteristic(UUID_SOME_SERVICE, UUID_SOME_CHAR)gattIo.enableNotification(char)
gattIo.writeCharacteristic(char, byteArrayOf(...))
val resp = gattIo.readCharacteristicChange(char)
println("response: ${resp.contentToString()}")
gattIo.disableNotificationOrIndication(char)gattIo.gatt.close()
}
```Real-world example:
[MiBand.kt](https://github.com/sorz/miband4-export/blob/master/app/src/main/java/cn/edu/sustech/cse/miband/MiBand.kt)## Debugging
Logs don't get printed by default. To enable logging, execute:```bash
adb shell setprop log.tag.GattIo debug
```