自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
自定义配件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Android 的配件可以是任何设备:键盘、温度计、机器人、照明控制系统或您可以想象到的任何设备。所有 Android 配件都以某种方式连接到 Android 设备,因此在构建配件时,您必须考虑配件将使用的连接类型。本页概括介绍了 Android 配件的连接选项,以及可帮助您快速入门的资源列表。
通过 USB 连接
通过 USB 线连接到 Android 设备的配件必须支持 Android 开源配件 (AOA) 协议,该协议指定了配件如何通过 USB 与 Android 设备建立通信。由于 Android 设备的输出功率较低,因此 AOA 需要配件充当 USB 主机,这意味着连接的配件必须为总线供电。
AOA 有两个支持不同通信类型的版本:
- AOAv1。支持通用配件通信和 adb 调试。
- AOAv2。支持人机接口设备 (HID) 功能。适用于 Android 4.1(API 级别 16)或更高版本。
如果您使用通用配件协议(而不是使用 adb 或音频协议)与配件通信,则必须提供可以检测 USB 配件连接并建立通信的 Android 应用。
后续步骤
开始构建使用 USB 连接的 Android 配件:
- 选择可支持 USB 主机模式的硬件平台或构建此类硬件设备。
- 查看 AOA 规范,了解如何在您的配件硬件上实现此协议。
- 查看 ADK 2012 固件源代码 (
<adk-src>/adk2012/board/library/ADK2/
),该代码展示了如何实现通过 USB 连接进行常规数据通信和音频流式传输的配件。
- 如果计划构建一款通过 USB 与您的配件通信的 Android 应用,请查看 ADK 2012 Android 应用源代码 (
<adk-src>/adk2012/app/
)。
通过蓝牙连接
通过蓝牙连接与 Android 设备连接的配件可以使用 Android 支持的连接配置文件,包括简单串行协议 (SSP) 和高级音频分发配置文件 (A2DP)。使用蓝牙连接到 Android 设备的配件必须支持蓝牙通信以及至少一个受支持的连接配置文件。
用户必须在 Android 设备上启用蓝牙功能,并与您的配件配对才能使用该配件。您还可以提供一个辅助 Android 应用,负责处理专门的通信(如数据输入或控制输出),以与您的配件进行连接。
后续步骤
开始构建使用蓝牙连接的 Android 配件:
- 选择可支持蓝牙通信和 Android 支持的连接配置文件(如 SSP 或 A2DP)的硬件平台或构建此类硬件设备。
- 查看 ADK 2012 固件源代码 (
<adk-src>/adk2012/board/library/ADK2/
),其中包含使用蓝牙连接进行常规数据通信和音频流式传输的一个示例实现。
- 如果计划构建一款通过蓝牙与您的配件通信的 Android 应用,请查看 ADK 2012 Android 应用源代码 (
<adk-src>/adk2012/app/
)。
注意:虽然 ADK 2012 源代码包含为 Texas Instruments CC2564 芯片构建的开放源代码蓝牙堆栈,但其旨在与支持标准主机/控制器接口 (HCI) 的任何蓝牙芯片配合使用。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[],[],null,["# Custom accessories\n\nAn accessory for Android can be anything: keyboard, thermometer, robot,\nlighting control, or anything else you can imagine. All Android accessories\nconnect to an Android device in some way, so when building an accessory you must\nconsider the type of connections your accessory will use. This page provides a\nquick overview of your options for connecting your Android accessory and\na list of resources to help you get started.\n\nConnect over USB\n----------------\n\nAn accessory that connects to an Android device through a USB cable must\nsupport the Android Open Accessory (AOA) protocol, which specifies how an\naccessory can establish communication with an Android device via USB.\nDue to the low power output of Android devices, AOA requires the accessory to\nact as a USB host, meaning the connecting accessory must power the bus.\n\nAOA has two versions that support different types of communication:\n\n- **[AOAv1](/docs/core/interaction/accessories/aoa).** Supports generic accessory communication and adb debugging.\n- **[AOAv2](/docs/core/interaction/accessories/aoa2).** Supports human interface device (HID) capabilities. Available in Android 4.1 (API Level 16) or higher.\n\nIf you use the general accessory protocol to communicate with your accessory\n(rather than the adb or audio protocol), you must provide an Android\napp that can detect the connection of your USB accessory and establish\ncommunication.\n\n### Next steps\n\nTo get started building an Android accessory that uses a USB connection:\n\n- Select a hardware platform or build a hardware device that can support USB host mode.\n- Review [AOA](/docs/core/interaction/accessories/protocol) specifications to understand how to implement this protocol on your accessory hardware.\n- Review the ADK 2012 [firmware\n source code](http://developer.android.com/tools/adk/adk2.html#src-download) (`\u003cadk-src\u003e/adk2012/board/library/ADK2/`), which demonstrates an implementation of an accessory using a USB connection for general data communications and audio streaming.\n- When planning to build an Android app that communicates with your accessory via USB, review the ADK 2012 Android [app\n source code](http://developer.android.com/tools/adk/adk2.html#src-download) (`\u003cadk-src\u003e/adk2012/app/`).\n\nConnect over Bluetooth\n----------------------\n\nAn accessory that connects with Android devices over a Bluetooth connection\ncan use connection profiles supported by Android, including the Simple Serial\nProtocol (SSP) and Advanced Audio Distribution Profile (A2DP) profile. An\naccessory that uses Bluetooth to connect to Android devices must support\nBluetooth communications and at least one of the supported connection profiles.\n\nUsers must enable Bluetooth on their Android device and pair with your\naccessory to use the accessory. You can also provide a secondary Android\napp that handles specialized communication such as data input or control\noutputs to interface with your accessory.\n\n### Next steps\n\nTo get started building an Android accessory that uses a Bluetooth connection:\n\n- Select a hardware platform or build an hardware device that can support Bluetooth communications and an Android supported connection profile, such as SSP or A2DP.\n- Review the ADK 2012 [firmware\n source code](http://developer.android.com/tools/adk/adk2.html#src-download) (`\u003cadk-src\u003e/adk2012/board/library/ADK2/`), which includes an example implementation of general data communications and audio streaming using a Bluetooth connection.\n- When planning to build an Android app that communicates with your accessory via Bluetooth, review the ADK 2012 Android [app\n source code](http://developer.android.com/tools/adk/adk2.html#src-download) (`\u003cadk-src\u003e/adk2012/app/`).\n\n**Note:** The ADK 2012 source code includes an open\nsource Bluetooth stack built for the Texas Instruments CC2564 chip but is\ndesigned to work with any Bluetooth chip that supports a standard\nHost/Controller Interface (HCI)."]]