Od 27 marca 2025 r. zalecamy używanie android-latest-release
zamiast aosp-main
do kompilowania i wspołtworzenia AOSP. Więcej informacji znajdziesz w artykule o zmianach w AOSP.
Bluetooth
Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Android udostępnia domyślny stos Bluetooth, który obsługuje zarówno Bluetooth Classic, jak i Bluetooth Low Energy (BLE). Urządzenia z Androidem mogą tworzyć osobiste sieci lokalne za pomocą Bluetootha, aby wysyłać i odbierać dane z urządzeń Bluetooth w pobliżu.
W Androidzie 4.3 i nowszym stos protokołów Bluetooth Androida umożliwia implementację BLE. Aby w pełni korzystać z interfejsów BLE API, postępuj zgodnie z wymaganiami dotyczącymi interfejsu HCI Bluetootha na Androidzie. Urządzenia z Androidem z odpowiednim chipsetem mogą obsługiwać klasyczną wersję Bluetootha lub obie wersje: klasyczną i BLE. BLE nie jest wstecznie zgodny ze starszymi chipsetami Bluetooth.
W Androidzie 8.0 stos Bluetootha jest w pełni zgodny ze standardem Bluetooth 5. Aby korzystać z dostępnych funkcji Bluetooth 5, urządzenie musi mieć certyfikowany chipset Bluetooth 5.
Architektura Androida
Aplikacja Bluetooth komunikuje się z procesem Bluetooth za pomocą interfejsu Binder. Proces Bluetooth
używa interfejsu Java Native Interface (JNI) do komunikacji ze stosem Bluetooth i zapewnia
programistom dostęp do różnych profili Bluetooth. Ten diagram przedstawia ogólną strukturę stosu Bluetooth:

Rysunek 1. Architektura Bluetootha na Androidzie.
- platforma aplikacji
-
Na poziomie struktury aplikacji znajduje się kod aplikacji, który korzysta z interfejsów API
android.bluetooth
do interakcji ze sprzętem Bluetooth. Wewnętrznie ten kod wywołuje proces Bluetooth za pomocą mechanizmu IPC Binder.
- Aplikacja Bluetooth
-
Aplikacja Bluetooth, znajdująca się w
packages/modules/Bluetooth/android/app
, jest pakowana jako aplikacja na Androida i implementuje profile Bluetootha na warstwie frameworka Androida. Ta aplikacja wywołuje stos Bluetooth za pomocą JNI.
- JNI
- Kod JNI powiązany z
android.bluetooth
znajduje się w packages/modules/Bluetooth/android/app/jni
. Kod JNI wywołuje stos Bluetooth, gdy występują określone operacje Bluetooth, np. gdy wykrywane są urządzenia.
- Stos Bluetooth
-
Domyślny stos Bluetooth jest dostępny w AOSP i znajduje się w
packages/modules/Bluetooth/system
. Stos implementuje ogólny interfejs HAL Bluetooth i dostosowuje go za pomocą rozszerzeń i zmian konfiguracji.
- wdrażanie dostawcy,
-
Urządzenia dostawcy komunikują się ze stosem Bluetooth za pomocą języka definicji interfejsu HAL (HIDL).
HIDL
HIDL definiuje interfejs między stosem Bluetooth a implementacją dostawcy. Aby wygenerować pliki HIDL Bluetooth, przekaż pliki interfejsu Bluetooth do narzędzia do generowania HIDL. Pliki interfejsu znajdują się w lokalizacji hardware/interfaces/bluetooth
.
Opracowywanie stosu Bluetooth
Stos Bluetooth w Androidzie jest w pełni kwalifikowanym stosem Bluetooth. Lista kwalifikacji znajduje się na stronie internetowej Bluetooth SIG (wymaga zalogowania) w sekcji QDID 169365.
Główny stos Bluetootha znajduje się w folderze
packages/modules/Bluetooth
. Rozwój odbywa się w ramach AOSP, a każde zaangażowanie w ten proces jest mile widziane.
Treść strony i umieszczone na niej fragmenty kodu podlegają licencjom opisanym w Licencji na treści. Java i OpenJDK są znakami towarowymi lub zastrzeżonymi znakami towarowymi należącymi do firmy Oracle lub jej podmiotów stowarzyszonych.
Ostatnia aktualizacja: 2025-08-22 UTC.
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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."]]