自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
藍牙
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 提供預設的藍牙堆疊,同時支援傳統藍牙和藍牙低功耗 (BLE)。Android 裝置可透過藍牙建立個人區域網路,與附近的藍牙裝置傳送及接收資料。
在 Android 4.3 以上版本中,Android Bluetooth 堆疊可實作 BLE。如要完整使用 BLE API,請遵循 Android Bluetooth HCI 規定。搭載合格晶片的 Android 裝置可以實作傳統藍牙,也可以同時實作傳統藍牙和 BLE。BLE 無法與舊版藍牙晶片組回溯相容。
在 Android 8.0 中,藍牙堆疊完全符合藍牙 5 的資格。如要使用藍牙 5 的功能,裝置必須具備藍牙 5 認證的晶片組。
Android 架構
藍牙應用程式會透過 Binder 與藍牙程序通訊。藍牙程序會使用 Java Native Interface (JNI) 與藍牙堆疊通訊,並讓開發人員存取各種藍牙設定檔。下圖顯示藍牙堆疊的一般結構:

圖 1. Android 藍牙架構。
- 應用程式架構
-
在應用程式架構層級,應用程式程式碼會使用
android.bluetooth
API 與藍牙硬體互動。在內部,這段程式碼會透過 Binder IPC 機制呼叫藍牙程序。
- 藍牙應用程式
-
藍牙應用程式位於
packages/modules/Bluetooth/android/app
,
封裝為 Android 應用程式,並在 Android 架構層實作藍牙設定檔。這個應用程式會透過 JNI 呼叫藍牙堆疊。
- JNI
-
與
android.bluetooth
相關聯的 JNI 程式碼位於 packages/modules/Bluetooth/android/app/jni
。發生特定藍牙作業時 (例如偵測到裝置),JNI 程式碼會呼叫藍牙堆疊。
- 藍牙堆疊
-
AOSP 提供預設藍牙堆疊,位於
packages/modules/Bluetooth/system
。堆疊會實作一般藍牙 HAL,並透過擴充功能和設定變更進行自訂。
- 廠商導入
-
供應商裝置會使用 HAL 介面定義語言 (HIDL) 與藍牙堆疊互動。
HIDL
HIDL 定義藍牙堆疊與供應商實作之間的介面。如要產生藍牙 HIDL 檔案,請將藍牙介面檔案傳遞至 HIDL 產生工具。介面檔案位於
hardware/interfaces/bluetooth
。
藍牙堆疊開發
Android 藍牙堆疊是完全合格的藍牙堆疊。資格清單位於 Bluetooth SIG 網站 (需要登入) 的 QDID 169365 下方。
核心藍牙堆疊位於
packages/modules/Bluetooth
中。開發作業會在 AOSP 中進行,歡迎貢獻內容。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-22 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-22 (世界標準時間)。"],[],[],null,["# Bluetooth\n\nAndroid provides a default Bluetooth stack that supports both Classic Bluetooth and Bluetooth\nLow Energy (BLE). Using Bluetooth, Android devices can create personal area networks to send\nand receive data with nearby Bluetooth devices.\n\n\nIn Android 4.3 and higher, the Android Bluetooth stack provides the ability to implement\nBLE. To fully use the BLE APIs, follow the\n[Android Bluetooth HCI Requirements](/docs/core/connect/bluetooth/hci_requirements). Android devices with a qualified chipset can implement either Classic Bluetooth or both\nClassic Bluetooth and BLE. BLE isn't backward compatible with older Bluetooth chipsets.\n\n\nIn Android 8.0, the Bluetooth stack is fully qualified for Bluetooth 5. To use\navailable Bluetooth 5 features, the device needs to have a Bluetooth 5 qualified chipset.\n\nAndroid architecture\n--------------------\n\n\nA Bluetooth app communicates with the Bluetooth process through Binder. The Bluetooth\nprocess uses Java Native Interface (JNI) to communicate with the Bluetooth stack and provides\ndevelopers with access to various Bluetooth profiles. This diagram shows the general\nstructure of the Bluetooth stack:\n\n**Figure 1.** Android Bluetooth architecture.\n\napp framework\n:\n At the app framework level is app code, which uses the\n [`android.bluetooth`](http://developer.android.com/reference/android/bluetooth/package-summary.html)\n APIs to interact with the Bluetooth hardware. Internally, this code calls the Bluetooth\n process through the Binder IPC mechanism.\n\nBluetooth app\n:\n The Bluetooth app, located in `packages/modules/Bluetooth/android/app`,\n is packaged as an Android app and implements the Bluetooth profiles at the Android framework\n layer. This app calls into the Bluetooth stack through JNI.\n\nJNI\n:\n The JNI code associated with `android.bluetooth` is located in\n `packages/modules/Bluetooth/android/app/jni`. The JNI code calls into the\n Bluetooth stack when certain Bluetooth operations occur, such as when devices are\n discovered.\n\nBluetooth stack\n:\n The default Bluetooth stack is provided in AOSP and is located in\n `packages/modules/Bluetooth/system`. The stack implements the generic Bluetooth\n HAL and customizes it with extensions and configuration changes.\n\nvendor implementation\n:\n Vendor devices interact with the Bluetooth stack using the HAL interface definition\n language (HIDL).\n\n### HIDL\n\n\n[HIDL](/docs/core/architecture/hidl) defines the interface between the\nBluetooth stack and the vendor implementation. To generate the Bluetooth HIDL files, pass the\nBluetooth interface files into the HIDL generation tool. The interface files are located in\n[`hardware/interfaces/bluetooth`](https://android.googlesource.com/platform/hardware/interfaces/+/android16-release/bluetooth/).\n\n### Bluetooth stack development\n\n\nThe Android Bluetooth stack is a fully qualified Bluetooth stack. The qualification listing is\non the Bluetooth SIG website (requires sign-in) under\n[QDID 169365](https://launchstudio.bluetooth.com/ListingDetails/130825).\n\n\nThe core Bluetooth stack resides in\n[packages/modules/Bluetooth](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Bluetooth/). Development happens in AOSP, and contributions are welcome."]]