使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
蓝牙
使用向后兼容的 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 中包含这些提交内容。
新功能
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 修复
版本 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 接口、清晰的线程模型以及异步和同步操作,并确保所有方法均会执行并提供结果。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# bluetooth\n=========\n\nAPI Reference \n[androidx.bluetooth](/reference/kotlin/androidx/bluetooth/package-summary) \nUse the Android platform's Bluetooth features with backward-compatible APIs. \n\n| Latest Update | Stable Release | Release Candidate | Beta Release | Alpha Release |\n|-------------------|----------------|-------------------|--------------|---------------------------------------------------------------------|\n| November 29, 2023 | - | - | - | [1.0.0-alpha02](/jetpack/androidx/releases/bluetooth#1.0.0-alpha02) |\n\nDeclaring dependencies\n----------------------\n\nTo add a dependency on Bluetooth, you must add the Google Maven repository to your\nproject. Read [Google's Maven repository](/studio/build/dependencies#google-maven)\nfor more information.\n\nAdd the dependencies for the artifacts you need in the `build.gradle` file for\nyour app or module: \n\n### Groovy\n\n```groovy\ndependencies {\n \n implementation \"androidx.bluetooth:bluetooth:1.0.0-alpha02\"\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencies {\n \n implementation(\"androidx.bluetooth:bluetooth:1.0.0-alpha02\")\n}\n```\n\nFor more information about dependencies, see [Add build dependencies](/studio/build/dependencies).\n\nFeedback\n--------\n\nYour feedback helps make Jetpack better. Let us know if you discover new issues or have\nideas for improving this library. Please take a look at the\n[existing issues](https://issuetracker.google.com/issues?q=componentid:1190075%20status:open)\nin this library before you create a new one. You can add your vote to an existing issue by\nclicking the star button.\n\n[Create a new issue](https://issuetracker.google.com/issues/new?component=1190075&template=1683949)\n\nSee the [Issue Tracker documentation](https://developers.google.com/issue-tracker)\nfor more information.\n\nThere are no release notes for this artifact.\n\nVersion 1.0\n-----------\n\n### Version 1.0.0-alpha02\n\nNovember 29, 2023\n\n`androidx.bluetooth:bluetooth:1.0.0-alpha02` and `androidx.bluetooth:bluetooth-testing:1.0.0-alpha02` are released. [Version 1.0.0-alpha02 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/91bb8c1f81dcb031bda00fcd8e55f1e890b56f06..b5166f9a1e9c047162d1215884c3e2cd41a4a74a/bluetooth)\n\n**New Features**\n\n- Lower `minSdkVersion` to 21\n\n**API Changes**\n\n- `GattServerConnectFlow#updateServices` becomes a suspend function ([I0237d](https://android-review.googlesource.com/#/q/I0237d90173df024f4052a781ba41dd72a9a54343))\n- Change `AdvertiseParams.durationMillis` to Long ([If6771](https://android-review.googlesource.com/#/q/If6771fb2a9de564dd194d62bf100420e4b6a16d0))\n- Convert `openGattServer` to Flow ([Icef54](https://android-review.googlesource.com/#/q/Icef5495059e5fd5d7db9aa1eed779b798142d2d8))\n- Throw `ScanException` on scan fail and set scanner to `setLegacy(false)` by default ([Ib337c](https://android-review.googlesource.com/#/q/Ib337c25327a8c2a9611352b804a8ae6c71a99656))\n- Throw `AdvertiseException` on advertise fail ([I0e691](https://android-review.googlesource.com/#/q/I0e691b67dfb11f0e67e6c61845f38b5a2bcfd44c))\n- Add general bluetooth exception to catch ([I0130d](https://android-review.googlesource.com/#/q/I0130d754ada8ec78577936ca65bbd56f97feb69c))\n- Convert advertise to Flow and change maximum duration ([I32fd8](https://android-review.googlesource.com/#/q/I32fd8522085028d20735749cd9ca2f18fcae9851))\n- Add `serviceData` and `serviceSolicitationUuids` to `ScanResult` ([I6d7f0](https://android-review.googlesource.com/#/q/I6d7f0a36e15b168a374ad3ea8d28f18bc6b7cb79))\n- Change `durationMillis` from Long to Duration ([I89d49](https://android-review.googlesource.com/#/q/I89d4936165a43600862521673605d2e533bc9677))\n- Add rssi, and `periodicAdvertisingInterval` to `ScanResult` ([I60b51](https://android-review.googlesource.com/#/q/I60b514a7893ec07bcc0eec2a8706e635c4c51c1f))\n- Add `serviceSolicitationUuid` and `solicitationUuidMask` to `ScanFilter` ([Ic2206](https://android-review.googlesource.com/#/q/Ic220683ef400b7d707424b250ef497194fad450d))\n- Added `GattServerSessionScope#subscribedCharacteristics` ([I0edab](https://android-review.googlesource.com/#/q/I0edabd53e1af3dcd64abd42470887a36de236144))\n- Add `serviceSolicitationUuids` to `AdvertiseParams` ([Ic9aa7](https://android-review.googlesource.com/#/q/Ic9aa78cad8da049ccfabbe48f468e5e193fbaad0))\n- Change `AdvertiseParams.durationMillis` from Int to Long ([I6873f](https://android-review.googlesource.com/#/q/I6873f3b2c222f02ab0f53c04e66c23a6106d86a5))\n- `GattServerSessionScope#notify` does not return but throws an exception if it fails ([Ifc26f](https://android-review.googlesource.com/#/q/Ifc26fac2a3b8fbd0aa404fb4e6d5d9fa4c59f9d5))\n\n**Bug Fixes**\n\n- Extract scan functionality ([I4d43f](https://android-review.googlesource.com/#/q/I4d43f370b201c942bea0eda1230fef7ff6ef8aca))\n\n### Version 1.0.0-alpha01\n\nSeptember 20, 2023\n\n`androidx.bluetooth:bluetooth:1.0.0-alpha01` and `androidx.bluetooth:bluetooth-testing:1.0.0-alpha01` are released. [Version 1.0.0-alpha01 contains these commits.](https://android.googlesource.com/platform/frameworks/support/+log/91bb8c1f81dcb031bda00fcd8e55f1e890b56f06/bluetooth)\n\n**New Features**\n\n- This is the initial release of AndroidX Bluetooth APIs that provides a Kotlin API surface covering Bluetooth LE scanning and advertising, and GATT client and server use cases. It provides a minimal API surface, clear thread model with async and sync operations, and ensures all methods be executed and provides the results."]]