title: Android: How to use webcam in emulator?
body: <p>I'm connecting a webcam to my emulator by setting the front camera to "webcam0" in the AVD Manager.  When I start the emulator's camera application, I get the error</p>
  
  <pre><code>CameraService::connect X (pid 702) rejected (invalid cameraId 0).
  </code></pre>
  
  <p>Here's the relevant portion of the Android source code:</p>
  
  <pre><code>sp&lt;ICamera&gt; CameraService::connect(
      const sp&lt;ICameraClient&gt;&amp; cameraClient, int cameraId) {
  
      int callingPid = getCallingPid();
  
      [...]
  
      if (cameraId &lt; 0 || cameraId &gt;= mNumberOfCameras) {
          LOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).",
              callingPid, cameraId);
          return NULL;
      }
  
      [...]
  }
  </code></pre>
  
  <p>The webcam has been correctly assigned an ID of 0 because there's only 1 camera. However, <code>mNumberOfCameras</code> is presumably still 0.  This means that the camera is being registered by the emulator, but it hasn't bothered to update the number of connected cameras.  </p>
  
  <p><strong>How can I connect a webcam so that it will be properly recognized by the emulator?</strong></p>
  
  <p>Edit: the command <code>emulator -webcam-list -avd &lt;name of your AVD&gt;</code> in <code>\android-sdks\tools</code> gives the result:</p>
  
  <pre><code>List of web cameras connected to the computer:
  Camera `webcam0` is connected to device `AndroidEmulatorVC0` on channel 0 using pixel format `BGR4`
  </code></pre>
  
  <p>When I launch the webcam from Eclipse's AVD manager or using <code>emulator -camera-front webcam0 -avd &lt;name of your AVD&gt;</code>, I get the following window: </p>
  
  <p><img src="https://i.stack.imgur.com/Y7Suc.png" alt="enter image description here"></p>
  
  <p>Edit 2: This seems to be a bug in the emulator. The suggested answer tells you what to do to set up the camera, but doesn't solve the problem for me.  I ultimately solved it by using a laptop with a built-in webcam.  Perhaps another USB webcam might have worked as well.</p>