自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
Android 作業系統識別
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
keywords: AiAssisted,release16,androidconnectivity,bluetooth,category:AndroidConnectivity,docType:Guide
從 Android 14 開始,Android 架構會納入名為 Android 資訊服務 (AIS) 的通用屬性 (GATT) 服務,讓藍牙裝置將 Android API 級別讀取為服務的 GATT 特徵。這項服務可讓藍牙裝置製造商瞭解藍牙周邊裝置是否與執行 Android OS 的中央裝置配對,並根據 API 級別管理專屬邏輯。
AIS 是標準 GATT 服務,裝置上只能有一個 AIS 例項。主要服務 UUID 為 e73e0001-ef1b-4e74-8291-2e4f3164f3b5
。
Android API 級別特徵 (UUID:e73e0002-ef1b-4e74-8291-2e4f3164f3b5
) 包含裝置的 API 級別,以二進位形式 (小端序) 的無正負號 32 位元整數表示。Android API 級別特徵的值長度為 4 個八位元 (例如,API 級別 36 為 0x24_00_00_00
)。裝置可供探索時,Android API 級別特徵值可供讀取,不需驗證或授權。如果裝置無法探索,Android API 層級特徵只能透過驗證和授權讀取。
探索服務
藍牙裝置扮演 GATT 用戶端角色,Android 裝置則扮演伺服器角色。如要探索 AIS 並讀取 Android API 級別,藍牙裝置會使用 GATT 設定檔程序,例如主要服務探索、特徵探索和特徵值讀取程序。如要進一步瞭解這些程序,請參閱 GATT 設定檔規格。
API 級別是由 ro.build.version.sdk
系統屬性定義。如果找不到主要服務,表示系統屬性未定義、值設為空白,或是主機作業系統不是 Android。
驗證
如要驗證是否可探索 AIS,請手動測試,方法是將藍牙周邊裝置與 Android 裝置配對,然後在探索到的主要服務中查詢 AIS 服務 UUID。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Android OS identification\n\nkeywords: AiAssisted,release16,androidconnectivity,bluetooth,category:AndroidConnectivity,docType:Guide\n\nStarting in Android 14, the Android framework includes a Generic Attribute\n(GATT) service called Android information service (AIS), which lets Bluetooth\ndevices read the Android API level as a GATT characteristic of the service.\nThis service lets Bluetooth device manufacturers know whether a Bluetooth\nperipheral is pairing with a central device that is running the Android OS,\nand manage specialized logic based on the API level.\n\nAndroid information service (AIS)\n---------------------------------\n\nAIS is a standard GATT service and there can be only one instance of AIS on\na device. The primary service UUID is `e73e0001-ef1b-4e74-8291-2e4f3164f3b5`.\nThe Android API level characteristic (UUID:\n`e73e0002-ef1b-4e74-8291-2e4f3164f3b5`) contains the API level of the device as\nan unsigned 32-bit integer in binary form (little-endian). The value of the\nAndroid API level characteristic is 4 octets in length (for example, API\nlevel 36 is `0x24_00_00_00`). When the device is discoverable, the Android API\nlevel characteristic value is readable without authentication or authorization.\nWhen the device isn't discoverable, the Android API level characteristic is\nreadable only with authentication and authorization.\n\nDiscover the service\n--------------------\n\nThe Bluetooth device is on the GATT client role and the Android-powered device\nis on the server role. To discover AIS and read the Android API level, Bluetooth\ndevices use GATT profile procedures such as the *primary service discovery* ,\n*characteristic discovery* , and *characteristic value read* procedures. For\ndetails on these procedures, see the [GATT profile specification](https://www.bluetooth.com/wp-content/uploads/Files/Specification/HTML/Core-54/out/en/host/generic-attribute-profile--gatt-.html).\n\nThe API level is defined by the `ro.build.version.sdk` system property. If the\nprimary service can't be discovered, it means that the system property isn't\ndefined or the value is set to empty, or the host operation system isn't\nAndroid.\n\nValidation\n----------\n\nTo verify that AIS can be discovered, run a manual test by pairing a Bluetooth\nperipheral with an Android-powered device, and then looking up the AIS service\nUUID in the discovered primary services."]]