Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Bluetooth
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Android cung cấp một ngăn xếp Bluetooth mặc định hỗ trợ cả Bluetooth cổ điển và Bluetooth năng lượng thấp (BLE). Bằng Bluetooth, các thiết bị Android có thể tạo mạng khu vực cá nhân để gửi và nhận dữ liệu với các thiết bị Bluetooth ở gần.
Trong Android 4.3 trở lên, ngăn xếp Bluetooth của Android cung cấp khả năng triển khai BLE. Để sử dụng đầy đủ các API BLE, hãy làm theo Yêu cầu về HCI Bluetooth của Android. Các thiết bị Android có chipset đủ tiêu chuẩn có thể triển khai Bluetooth truyền thống hoặc cả Bluetooth truyền thống và BLE. BLE không tương thích ngược với các chipset Bluetooth cũ.
Trong Android 8.0, ngăn xếp Bluetooth hoàn toàn đủ điều kiện cho Bluetooth 5. Để sử dụng các tính năng Bluetooth 5 hiện có, thiết bị cần có một chipset đạt tiêu chuẩn Bluetooth 5.
Cấu trúc Android
Ứng dụng Bluetooth giao tiếp với quy trình Bluetooth thông qua Binder. Quy trình Bluetooth sử dụng Giao diện gốc của Java (JNI) để giao tiếp với ngăn xếp Bluetooth và cho phép nhà phát triển truy cập vào nhiều cấu hình Bluetooth. Sơ đồ này cho thấy cấu trúc chung của ngăn xếp Bluetooth:

Hình 1. Cấu trúc Bluetooth của Android.
- khung ứng dụng
-
Ở cấp độ khung ứng dụng là mã ứng dụng, sử dụng các API
android.bluetooth
để tương tác với phần cứng Bluetooth. Trong nội bộ, mã này gọi quy trình Bluetooth thông qua cơ chế Binder IPC.
- Ứng dụng Bluetooth
-
Ứng dụng Bluetooth, nằm trong
packages/modules/Bluetooth/android/app
, được đóng gói dưới dạng một ứng dụng Android và triển khai các hồ sơ Bluetooth ở lớp khung Android. Ứng dụng này gọi vào ngăn xếp Bluetooth thông qua JNI.
- JNI
-
Mã JNI liên kết với
android.bluetooth
nằm trong packages/modules/Bluetooth/android/app/jni
. Mã JNI gọi vào ngăn xếp Bluetooth khi một số thao tác Bluetooth xảy ra, chẳng hạn như khi các thiết bị được phát hiện.
- Ngăn xếp Bluetooth
-
Ngăn xếp Bluetooth mặc định được cung cấp trong AOSP và nằm trong
packages/modules/Bluetooth/system
. Ngăn xếp này triển khai HAL Bluetooth chung và tuỳ chỉnh HAL đó bằng các tiện ích và thay đổi về cấu hình.
- triển khai của nhà cung cấp
-
Các thiết bị của nhà cung cấp tương tác với ngăn xếp Bluetooth bằng ngôn ngữ định nghĩa giao diện HAL (HIDL).
HIDL
HIDL xác định giao diện giữa ngăn xếp Bluetooth và quá trình triển khai của nhà cung cấp. Để tạo các tệp HIDL Bluetooth, hãy truyền các tệp giao diện Bluetooth vào công cụ tạo HIDL. Các tệp giao diện nằm trong hardware/interfaces/bluetooth
.
Phát triển ngăn xếp Bluetooth
Ngăn xếp Bluetooth Android là một ngăn xếp Bluetooth đủ điều kiện. Danh sách đủ điều kiện có trên trang web của Bluetooth SIG (bạn phải đăng nhập) trong phần QDID 169365.
Ngăn xếp Bluetooth cốt lõi nằm trong
packages/modules/Bluetooth
. Quá trình phát triển diễn ra trong AOSP và chúng tôi hoan nghênh mọi đóng góp.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-22 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-22 UTC."],[],[],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."]]