android kotlin Compose 蓝牙库推荐

Kotlin + Compose 项目

// BLE 扫描(Android 4.3 ~ 14 兼容)

implementation "no.nordicsemi.android.support.v18:scanner:1.6.0"

// BLE 连接 / GATT / 读写 / Notify(核心)

implementation "no.nordicsemi.android:ble:2.10.2"

// Kotlin 协程支持(suspend / Flow)

implementation "no.nordicsemi.android:ble-ktx:2.10.2"

如果用到 下面的库可以选择依赖

// 只有老 LiveData 架构才要

implementation "no.nordicsemi.android:ble-livedata:2.10.2"

// 公共常量(通常会被 ble 自动传递)

implementation "no.nordicsemi.android:ble-common:2.10.2"

权限

扫描

val scanner = BluetoothLeScannerCompat.getScanner()

scanner.startScan(

null,

ScanSettings.Builder().build(),

scanCallback

)

连接 继承 BleManager)

class MyBleManager(

context: Context

) : BleManager(context) {

复制代码
override fun getGattCallback(): BleManagerGattCallback {
    return object : BleManagerGattCallback() {
        override fun onServicesDiscovered(device: BluetoothDevice, services: List<BluetoothGattService>) {
            // 找到你的 Service / Characteristic
        }
    }
}

}

读 / 写 / notify

writeCharacteristic(characteristic, data)

readCharacteristic(characteristic)

enableNotifications(characteristic)

相关推荐
有同事要进步3 小时前
gitee上面克隆项目出现错误
gitee
码农coding3 小时前
android12 systemUI 之锁屏
android
圆山猫3 小时前
[Virtualization](三):RISC-V H-extension 与 Guest 执行模式
android·java·risc-v
爱笑鱼4 小时前
Binder(七):getCallingUid() 读到的是谁?clearCallingIdentity() 又清掉了什么?
android
2501_915909069 小时前
iOS 应用反调试技详解术 检测调试器的原理与防护实践
android·ios·小程序·https·uni-app·iphone·webview
潘正翔9 小时前
k8s进阶_Harbor镜像仓库
git·云原生·容器·kubernetes·gitee·github
Lvan的前端笔记10 小时前
AndroidX 完全入门指南
android·androidx
Pniubi10 小时前
Gitee&GitHub同步仓库教程
gitee·github
帅次10 小时前
Android 应用高级面试:Window 近1年高频追问 18 题
android·面试·职场和发展
总捣什么乱111 小时前
MySQL MySQL是怎么保证主备一致的?
android·mysql·adb