USB 主機和配件總覽
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Android 透過以下兩種模式支援各種 USB 週邊裝置和 Android USB 配件 (實作 Android 配件通訊協定的硬體):USB 配件和 USB 主機。在 USB 配件模式下,外部 USB 硬體可做為 USB 主機。相關配件可能包括:
- 機器人控制器
- 充電站
- 診斷與音樂設備
- 資訊站
- 讀卡機
以及其他工具這可讓沒有主機功能的 Android 裝置與 USB 硬體互動。Android USB 配件必須設計能夠與 Android 裝置搭配使用,並遵循 Android 配件通訊協定。在 USB 主機模式下,Android 裝置會做為主機。裝置範例包括數位相機、鍵盤、滑鼠和遊戲控制器。專為多種應用程式和環境設計的 USB 裝置,仍可與能正確與裝置通訊的 Android 應用程式互動。
圖 1 顯示了這兩種模式之間的差異。當 Android 裝置處於主機模式時,就是 USB 主機並供電公車使用。當 Android 裝置處於 USB 配件模式時,連接的 USB 硬體 (在本例中為 Android USB 配件) 就是主機並供電公車。

圖 1 USB 主機和配件模式
Android 3.1 (API 級別 12) 以上版本平台直接支援 USB 配件和主機模式。USB 配件模式也是向後移植至 Android 2.3.4 (API 級別 10) 的外掛程式程式庫,以便支援更多的裝置。裝置製造商可選擇是否要在裝置的系統映像檔中加入外掛程式程式庫。
注意:無論平台層級為何,對於 USB 主機和配件模式的支援,最終還是取決於裝置的硬體。您可以透過 <uses-feature>
元素篩選支援 USB 主機和配件的裝置。詳情請參閱 USB 配件和主機說明文件。
偵錯注意事項
對使用 USB 配件或主機功能的應用程式進行偵錯時,您很可能有將 USB 硬體連接到 Android 裝置。如此可避免您使用 USB adb
連線至 Android 裝置。你仍然可以透過網路連線存取 adb
。如要透過網路連線啟用 adb
,請按照下列步驟操作:
- 使用 USB 連接 Android 裝置到電腦。
- 從 SDK
platform-tools/
目錄的命令提示字元中輸入 adb tcpip 5555
。
- 輸入
adb connect <device-ip-address>:5555
現在應連線至 Android 裝置,並可發出一般的 adb
指令,例如 adb logcat
。
- 如要設定裝置以透過 USB 聆聽訊息,請輸入
adb usb
。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","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-26 (世界標準時間)。"],[],[],null,["# USB host and accessory overview\n\nAndroid supports a variety of USB peripherals and Android USB accessories\n(hardware that implements the Android accessory protocol) through two modes: USB\naccessory and USB host. In USB accessory mode, the external USB hardware acts as\nthe USB host. Examples of accessories might include:\n\n- robotics controllers\n- docking stations\n- diagnostic and musical equipment\n- kiosks\n- card readers\n\nand many more. This gives Android-powered devices that don't have host\ncapabilities the ability to interact with USB hardware. Android\nUSB accessories must be\ndesigned to work with Android-powered devices and must adhere to the [Android\naccessory communication protocol](http://accessories.android.com/demokit). In\nUSB host mode, the Android-powered device acts as the host. Examples of devices\ninclude digital cameras, keyboards, mice, and game controllers. USB devices that\nare designed for a wide range of applications and environments can still\ninteract with Android applications that can correctly communicate with the\ndevice.\n\nFigure 1 shows the differences between the two modes. When the Android-powered\ndevice is in host mode, it acts as the USB host and powers the bus. When the\nAndroid-powered device is in USB accessory mode, the connected USB hardware (an\nAndroid USB accessory in this case) acts as the host and powers the bus.\n\n**Figure 1.** USB Host and Accessory Modes\n\nUSB accessory and host modes are directly supported in Android 3.1 (API level\n12) or newer platforms. USB accessory mode is also backported to Android 2.3.4\n(API level 10) as an add-on library to support a broader range of devices.\nDevice manufacturers can choose whether or not to include the add-on library on\nthe device\\\\'s system image.\n\n**Note:** Support for USB host and accessory modes are ultimately dependant on\nthe device\\\\'s hardware, regardless of platform level. You can filter for devices\nthat support USB host and accessory through a\n[`\u003cuses-feature\u003e`](/guide/topics/manifest/uses-feature-element) element.\nSee the USB [accessory](/develop/connectivity/usb/accessory) and\n[host](/develop/connectivity/usb/host) documentation for more details.\n\nDebug considerations\n--------------------\n\nWhen debugging applications that use USB accessory or host features, you most\nlikely have USB hardware connected to your Android-powered device. This\nprevents you from having an `adb` connection to the Android-powered device\nusing USB. You can still access `adb` over a network connection. To enable `adb`\nover a network connection:\n\n1. Connect the Android-powered device using USB to your computer.\n2. From your SDK `platform-tools/` directory, enter `adb tcpip 5555` at the command prompt.\n3. Enter `adb connect \u003cdevice-ip-address\u003e:5555` You should now be connected to the Android-powered device and can issue the usual `adb` commands like `adb logcat`.\n4. To set your device to listen on USB, enter `adb usb`."]]