自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
自訂配件
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 的配件可以是任何東西:鍵盤、溫度計、機器人、燈光控制器或其他任何你能想到的東西。所有 Android 配件都會以某種方式連線至 Android 裝置,因此在建構配件時,您必須考量配件將使用的連線類型。本頁面提供 Android 配件連線選項的快速總覽,以及可協助您快速上手的資源清單。
透過 USB 連線
透過 USB 傳輸線連接至 Android 裝置的配件必須支援 Android Open Accessory (AOA) 通訊協定,該協定會指定配件如何透過 USB 與 Android 裝置建立通訊。由於 Android 裝置的電力輸出量偏低,因此 AOA 要求配件必須充當 USB 主機,也就是說,連接的配件必須為匯流排供電。
AOA 有兩個版本,可支援不同類型的通訊:
- AOAv1。支援一般配件通訊和 ADB 偵錯。
- AOAv2。支援人機介面裝置 (HID) 功能。適用於 Android 4.1 (API 級別 16) 以上版本。
如果您使用一般配件通訊協定 (而非 ADB 或音訊通訊協定) 與配件通訊,則必須提供 Android 應用程式,以便偵測 USB 配件的連線,並建立通訊。
後續步驟
如要開始建構使用 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/
)。
注意:ADTK 2012 原始碼包含為德州儀器 CC2564 晶片建構的開放原始碼藍牙堆疊,但設計用於支援標準主機/控制器介面 (HCI) 的任何藍牙晶片。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","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-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)."]]