蓝牙
使用向后兼容的 API 使用 Android 平台的蓝牙功能。
| 最近更新时间 | 稳定版 | 候选版 | Beta 版 | Alpha 版 |
|---|---|---|---|---|
| 2023 年 11 月 29 日 | - | - | - | 1.0.0-alpha02 |
声明依赖项
如需添加 Bluetooth 的依赖项,您必须将 Google Maven 制品库添加到项目中。如需了解详情,请参阅 Google 的 Maven 代码库。
在应用或模块的 build.gradle 文件中添加所需工件的依赖项:
Groovy
dependencies { implementation "androidx.bluetooth:bluetooth:1.0.0-alpha02" }
Kotlin
dependencies { implementation("androidx.bluetooth:bluetooth:1.0.0-alpha02") }
如需详细了解依赖项,请参阅添加 build 依赖项。
反馈
您的反馈将帮助我们改进 Jetpack。如果您发现了新问题,或对此库有任何改进建议,请告诉我们。创建新问题前,请先查看此库中的现有问题。您可以点击星标按钮,为现有问题投票。
如需了解详情,请参阅问题跟踪器文档。
此工件没有版本说明。
版本 1.0
版本 1.0.0-alpha02
2023 年 11 月 29 日
发布了 androidx.bluetooth:bluetooth:1.0.0-alpha02 和 androidx.bluetooth:bluetooth-testing:1.0.0-alpha02。版本 1.0.0-alpha02 中包含这些提交内容。
新功能
- 将
minSdkVersion降低到 21
API 变更
GattServerConnectFlow#updateServices变为挂起函数 (I0237d)- 将
AdvertiseParams.durationMillis更改为 Long(If6771) - 将
openGattServer转换为 Flow (Icef54) - 在扫描失败时抛出
ScanException,并默认将扫描器设置为setLegacy(false)(Ib337c) - 在广告投放失败时抛出
AdvertiseException(I0e691) - 添加了要捕获的通用蓝牙异常 (I0130d)
- 将广告转换为广告连播并更改时长上限 (I32fd8)
- 向
ScanResult添加了serviceData和serviceSolicitationUuids(I6d7f0) - 将
durationMillis从“长”更改为“时长”(I89d49) - 向
ScanResult添加了 rssi 和periodicAdvertisingInterval(I60b51) - 向
ScanFilter添加了serviceSolicitationUuid和solicitationUuidMask(Ic2206) - 添加了
GattServerSessionScope#subscribedCharacteristics(I0edab) - 向
AdvertiseParams添加了serviceSolicitationUuids(Ic9aa7) - 将
AdvertiseParams.durationMillis从 Int 更改为 Long (I6873f) GattServerSessionScope#notify不会返回,但会在失败时抛出异常 (Ifc26f)
bug 修复
- 提取扫描功能 (I4d43f)
版本 1.0.0-alpha01
2023 年 9 月 20 日
发布了 androidx.bluetooth:bluetooth:1.0.0-alpha01 和 androidx.bluetooth:bluetooth-testing:1.0.0-alpha01。版本 1.0.0-alpha01 中包含这些提交内容。
新功能
- 这是 AndroidX Bluetooth API 的初始版本,提供涵盖蓝牙 LE 扫描和广告以及 GATT 客户端和服务器用例的 Kotlin API Surface。它提供了最少的 API 接口、清晰的线程模型以及异步和同步操作,并确保所有方法均会执行并提供结果。