自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
Android OS 识别
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-22。
[null,null,["最后更新时间 (UTC):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."]]