نظرة عامة حول مضيف وملحق USB
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
يتوافق Android مع مجموعة متنوعة من أجهزة USB الطرفية وملحقات USB من Android
(الأجهزة التي تتّبع بروتوكول ملحقات Android) من خلال وضعَين: ملحق USB
ومضيف USB. في وضع ملحق USB، تعمل أجهزة USB الخارجية كمضيف USB. في ما يلي أمثلة على الملحقات:
- وحدات تحكم في الروبوتات
- محطات مواقف دراجات
- المعدات التشخيصية والموسيقية
- أكشاك
- أجهزة قراءة البطاقات
وغير ذلك الكثير. وهذا يمنح الأجهزة التي تعمل بنظام تشغيل Android ولا تتمتع بإمكانيات المضيف
إمكانية التفاعل مع أجهزة USB. يجب تصميم ملحقات USB
على Android لتعمل مع الأجهزة التي تعمل بنظام التشغيل Android، ويجب أن تكون متوافقة مع بروتوكول الاتصال بملحقات Android. في
وضع مضيف USB، يعمل الجهاز الذي يعمل بنظام التشغيل Android كمضيف. ومن أمثلة الأجهزة الكاميرات الرقمية ولوحات المفاتيح وأجهزة الماوس ووحدات التحكم في الألعاب. لا يزال بإمكان أجهزة USB المصمَّمة لمجموعة واسعة من التطبيقات والبيئات التفاعل مع تطبيقات Android التي يمكنها الاتصال بالجهاز بشكل صحيح.
يوضح الشكل 1 الاختلافات بين الوضعين. عندما يكون الجهاز الذي يعمل بنظام التشغيل Android في وضع المضيف، فإنه يعمل كمضيف USB ويشغِّل الناقل. عندما يكون الجهاز الذي يعمل بنظام التشغيل Android في وضع ملحق USB، تعمل أجهزة USB المتصلة (أحد ملحقات USB من Android في هذه الحالة) كمضيف وتشغّل الناقل.

الشكل 1. مضيف USB وأوضاع الملحق
تتوافق أوضاع المضيف وملحقات USB مباشرةً في Android 3.1 (المستوى 12 من واجهة برمجة التطبيقات) أو الأنظمة الأساسية الأحدث. ويتم أيضًا نقل وضع ملحق USB إلى الإصدار Android 2.3.4
(المستوى 10 من واجهة برمجة التطبيقات) كمكتبة إضافات لإتاحة مجموعة أكبر من الأجهزة.
يمكن للشركات المصنّعة للأجهزة اختيار ما إذا كان سيتم تضمين مكتبة الإضافات في صورة نظام الجهاز أم لا.
ملاحظة: يعتمد دعم أوضاع مضيف USB وملحقاته في الأساس على مكونات الجهاز، بغض النظر عن مستوى النظام الأساسي. يمكنك فلترة الأجهزة
التي تتوافق مع مضيف USB وملحقاته من خلال عنصر
<uses-feature>
.
راجِع وثائق ملحق USB والمضيف لمزيد من التفاصيل.
اعتبارات تصحيح الأخطاء
عند تصحيح أخطاء التطبيقات التي تستخدم ملحق USB أو ميزات المضيف، من المرجح أن يكون لديك جهاز USB متصل بجهازك الذي يعمل بنظام التشغيل Android. ويمنعك ذلك من إنشاء اتصال adb
بالجهاز الذي يعمل بنظام التشغيل Android
باستخدام USB. ولا يزال بإمكانك الوصول إلى adb
عبر الاتصال بالشبكة. لتفعيل ميزة adb
عبر اتصال شبكة:
- عليك توصيل الجهاز الذي يعمل بنظام التشغيل Android باستخدام USB بالكمبيوتر.
- من دليل
platform-tools/
لحزمة SDK، أدخِل 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`."]]