ภาพรวมโฮสต์ USB และอุปกรณ์เสริม
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Android รองรับอุปกรณ์ต่อพ่วง USB และอุปกรณ์เสริม USB ของ Android ที่หลากหลาย
(ฮาร์ดแวร์ที่ใช้โปรโตคอลอุปกรณ์เสริมของ Android) ผ่าน 2 โหมด ได้แก่ อุปกรณ์เสริม USB และโฮสต์ USB ในโหมดอุปกรณ์เสริม USB ฮาร์ดแวร์ USB ภายนอกจะทำหน้าที่เป็น
โฮสต์ USB ตัวอย่างอุปกรณ์เสริมมีดังนี้
- ตัวควบคุมหุ่นยนต์
- แท่นชาร์จ
- อุปกรณ์วินิจฉัยและอุปกรณ์ดนตรี
- คีออสก์
- เครื่องอ่านบัตร
และอื่นๆ อีกมากมาย ซึ่งจะช่วยให้อุปกรณ์ที่ใช้ Android ที่ไม่มีความสามารถของโฮสต์
โต้ตอบกับฮาร์ดแวร์ USB ได้ อุปกรณ์เสริม USB ของ Android
ต้องออกแบบมาให้ใช้ได้กับอุปกรณ์ที่ใช้ Android และต้องเป็นไปตามโปรโตคอลการสื่อสารของอุปกรณ์เสริม Android ใน
โหมดโฮสต์ USB อุปกรณ์ที่ใช้ Android จะทำหน้าที่เป็นโฮสต์ ตัวอย่างอุปกรณ์
ได้แก่ กล้องดิจิทัล แป้นพิมพ์ เมาส์ และอุปกรณ์ควบคุมเกม อุปกรณ์ USB ที่
ออกแบบมาสำหรับแอปพลิเคชันและสภาพแวดล้อมที่หลากหลายยังคง
โต้ตอบกับแอปพลิเคชัน Android ที่สื่อสารกับ
อุปกรณ์ได้อย่างถูกต้อง
รูปที่ 1 แสดงความแตกต่างระหว่าง 2 โหมด เมื่ออุปกรณ์ที่ใช้ Android
อยู่ในโหมดโฮสต์ อุปกรณ์จะทำหน้าที่เป็นโฮสต์ USB และจ่ายไฟให้กับบัส เมื่ออุปกรณ์ที่ใช้ Android อยู่ในโหมดอุปกรณ์เสริม USB ฮาร์ดแวร์ USB ที่เชื่อมต่อ (อุปกรณ์เสริม USB ของ Android ในกรณีนี้) จะทำหน้าที่เป็นโฮสต์และจ่ายไฟให้กับบัส

รูปที่ 1 โหมดโฮสต์และอุปกรณ์เสริม USB
แพลตฟอร์ม Android 3.1 (API ระดับ
12) ขึ้นไปรองรับโหมดอุปกรณ์เสริม USB และโฮสต์โดยตรง นอกจากนี้ โหมดอุปกรณ์เสริม USB ยังได้รับการพอร์ตไปยัง Android 2.3.4
(API ระดับ 10) เป็นไลบรารีเสริมเพื่อรองรับอุปกรณ์ที่หลากหลายมากขึ้น
ผู้ผลิตอุปกรณ์สามารถเลือกได้ว่าจะรวมไลบรารีส่วนเสริมไว้ในอิมเมจระบบของอุปกรณ์หรือไม่
หมายเหตุ: การรองรับโหมดโฮสต์ USB และโหมดอุปกรณ์เสริมจะขึ้นอยู่กับฮาร์ดแวร์ของอุปกรณ์ในท้ายที่สุด ไม่ว่าจะเป็นระดับแพลตฟอร์มใดก็ตาม คุณสามารถกรองอุปกรณ์
ที่รองรับโฮสต์ USB และอุปกรณ์เสริมผ่านองค์ประกอบ
<uses-feature>
ได้
ดูรายละเอียดเพิ่มเติมในเอกสารประกอบเกี่ยวกับอุปกรณ์เสริมและโฮสต์ USB
ข้อควรพิจารณาในการแก้ไขข้อบกพร่อง
เมื่อแก้ไขข้อบกพร่องของแอปพลิเคชันที่ใช้ฟีเจอร์อุปกรณ์เสริมหรือโฮสต์ USB คุณมักจะเชื่อมต่อฮาร์ดแวร์ USB กับอุปกรณ์ที่ใช้ Android ซึ่งจะ
ป้องกันไม่ให้คุณเชื่อมต่อ adb
กับอุปกรณ์ที่ใช้ Android
ผ่าน USB คุณยังคงเข้าถึง adb
ผ่านการเชื่อมต่อเครือข่ายได้ วิธีเปิดใช้ adb
ผ่านการเชื่อมต่อเครือข่าย
- เชื่อมต่ออุปกรณ์ที่ใช้ Android กับคอมพิวเตอร์โดยใช้ USB
- จากไดเรกทอรี
platform-tools/
ของ SDK ให้ป้อน adb tcpip 5555
ที่
Command Prompt
- ป้อน
adb connect <device-ip-address>:5555
ตอนนี้คุณควรเชื่อมต่อกับ
อุปกรณ์ที่ใช้ Android และออกคำสั่ง adb
ตามปกติได้แล้ว เช่น
adb logcat
- หากต้องการตั้งค่าอุปกรณ์ให้ฟังผ่าน USB ให้ป้อน
adb usb
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","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 UTC"],[],[],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`."]]