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
CameraService::connect X (pid 702) rejected (invalid cameraId 0).
Here's the relevant portion of the Android source code:
sp<ICamera> CameraService::connect( const sp<ICameraClient>& cameraClient, int cameraId) { int callingPid = getCallingPid(); [...] if (cameraId < 0 || cameraId >= mNumberOfCameras) { LOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).", callingPid, cameraId); return NULL; } [...] }
The webcam has been correctly assigned an ID of 0 because there's only 1 camera. However, mNumberOfCameras
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.
How can I connect a webcam so that it will be properly recognized by the emulator?
Edit: the command emulator -webcam-list -avd <name of your AVD>
in \android-sdks\tools
gives the result:
List of web cameras connected to the computer: Camera `webcam0` is connected to device `AndroidEmulatorVC0` on channel 0 using pixel format `BGR4`
When I launch the webcam from Eclipse's AVD manager or using emulator -camera-front webcam0 -avd <name of your AVD>
, I get the following window:
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.
You need to edit your AVD so that in the hardware section either "Configures camera facing front" or "Configures camera facing back" are available. One, but not both, of the values for these properties should be set to "webcam0" (or whatever is available).
How Do I Enable The Camera On My Emulator? To edit (pencil) in Android Studio's actions, open the AVD Manager and then click on edit. In the next window, go to Advanced settings, then scroll down and in the camera settings option, click back on webcam.
UPDATE
In Android Studio AVD:
Follow the below steps in Eclipse.
Check here for more information : How to use web camera in android emulator to capture a live image?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With