title: Android Emulator (Android Studio AVD) Serial Port Connection - Empty Device List
body: <p>I'm trying to use the emulator that comes with Android Studio to open a serial port to talk to an Arduino board on COM5; however, I am having trouble even seeing a device list. I am using the package by <code>felHR85</code> <a href="https://github.com/felHR85/UsbSerial" rel="nofollow noreferrer">GitHub link</a> for the USB serial connection.</p>
  <p>I start by opening the emulator via the command line <code>emulator -avd Nexus_9_API_27 -qemu -serial COM5</code> which then opens the following dialog box:</p>
  <p><a href="https://i.stack.imgur.com/Vi6U1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vi6U1.png" alt="com5 emulator dialog box" /></a></p>
  <p>After accepting the defaults, I then run the application on the emulator and tap a button which runs the following code:</p>
  <pre><code>private void start() {
          HashMap&lt;String, UsbDevice&gt; usbDeviceHashMap = usbManager.getDeviceList();
          Log.i(TAG, &quot;start: &quot; + usbDeviceHashMap.size());
          if (!usbDeviceHashMap.isEmpty()) {
              Log.i(TAG, &quot;list not empty&quot;);
          }
  }
  </code></pre>
  <p>However, the <code>usbDeviceHashMap</code> is always empty - which is confirmed by my first log returning <code>start: 0</code> and my second log never being triggered.</p>
  <p>The <code>usbManager</code> is instantiated as follows: <code>usbManager = (UsbManager) getSystemService(this.USB_SERVICE);</code></p>
  <p>The application manifest (simplified):</p>
  <pre><code>&lt;uses-feature android:name=&quot;android.hardware.usb.host&quot;
          android:required=&quot;true&quot;/&gt;
      &lt;application
          ...&gt;
          &lt;activity android:name=&quot;.MainActivity&quot;&gt;
              ...
  
              &lt;meta-data android:name=&quot;android.hardware.usb.action.USB_DEVICE_ATTACHED&quot;
                  android:resource=&quot;@xml/device_filter&quot; /&gt;
  </code></pre>
  <p>The <code>@xml/device_filter</code> is:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;resources&gt;
      &lt;usb-device vendor-id=&quot;2341&quot; /&gt;
      &lt;!-- Vendor ID of Arduino --&gt;
  &lt;/resources&gt;
  </code></pre>
  <p>I'm not sure what is going wrong, I'm unable to test the code on a real device as the OTG connection piece is still in the mail.</p>
  <hr />
  <p>Windows 10, Android Studio v 4.1.1, Emulator API 27, Application Compile and Target SDK 30, Application Min SDK 26</p>
  <hr />
  <p><strong>UPDATE 17 DEC 2020:</strong>
  My OTG adapter arrived and I've tested the code, which works. No idea why the AVD Emulator doesn't work, it's a little frustrating but not the end of the world.</p>