Android Emulator: Unable to start webcam to capture picture in emulator
Solution 1
In Android Studio, go to AVD Manager, click on edit (pencil) button in Actions. After that, in next appearing window, click on Advance settings, and then scroll down and in Camera options, select webcam for front and back.
Solution 2
To enable Camera in your Android Emulator, just add following highlighted code in your AVD’s config.ini file. You can find the config.ini
file under your <userdirectory>/.android
folder.
File: ~/.android/config.ini
hw.lcd.density=160<br>
skin.name=HVGA<br>
skin.path=platforms\android-9\skins\HVGA<br>
hw.cpu.arch=arm<br>
abi.type=armeabi<br>
vm.heapSize=24<br>
image.sysdir.1=platforms\android-9\images\<br>
hw.camera=yes<br>
sdcard.size=64M<br>
In case you don’t find the config.ini
file or want to enable Camera support through Android SDK and AVD Manager do the following:
Open Android SDK and AVD Manager:
- Add SD Card in AVD
In the SD Card setting, set the value for Size. To enable camera, the SD Card must be enabled in Emulator. - Add Camera Support in Hardware under AVD
Now under Hardware section, click New button to add Camera hardware. It will open following Dialog box. Select Camera support from the Property dropdown and click Ok. - Enable Camera Support in Hardware
The new hardware: Camera support is visible under Hardware section. Set its value to yes and save changes by pressing Edit AVD. - Save the changes and launch the emulator.
Solution 3
You can try to manually edit your AVD's configuration file under
~/.android/avd/yourAvdName/config.ini
by adding this line:
hw.camera=yes
UPDATE
You can try to specify the real resolution of your webcam:
hw.camera.maxHorizontalPixels=XXX
hw.camera.maxVerticalPixels=XXX
Keep in mind that the default value for maxHorizontalPixels is 640 and for maxVerticalPixels is 480, so chaning this values may help you to solve your issues.
Solution 4
I had a similar issue with a slightly different error message under OS X. I turned out that everything was ok but the emulator is crashing when the camera takes too much time to initialize.
I my case I ended up closing other applications and it worked. You may want to test in a more performant computer.
Alessandro Roaro
Updated on December 13, 2020Comments
-
Alessandro Roaro over 3 years
I have created an armeabi API 21 emulator in the AVD manager in Android Studio, set it to use the webcam as a front camera, and launched it. The problem is that it's not able to open it, as I'm getting this error:
emulator: ERROR: camera_device_start_capturing: VIDIOC_STREAMON on camera '/dev/video0' has failed: Timer expired emulator: ERROR: _camera_client_query_start: Cannot start camera '/dev/video0' for NV21[640x480]: Inappropriate ioctl for device
How can I solve this?
The webcam works normally using other software. The operative system is Ubuntu 14.04.
-
Jon about 9 yearsWe don't have the issue of activating the camera. The camera is activated, but there seems to be an issue with drivers. There camera works with VLC and cheese. But it does not work within the emulator. However, the camera is detected by the system.
-
ManirajSS almost 9 yearsany idea for Visual studio AVD ?
-
Mayavi almost 9 years
-
Alessandro Roaro over 8 yearsAs I said, I configured the emulator to use the front camera. Thanks anyway
-
Alexander Haroldo da Rocha about 6 years
hw.camera=yes
fixed my problem! Tks! Strangely, if you save your AVD configurations using the AVD manager, it removes thehw.camera=yes
var. o.O -
Quigi over 5 yearsI read a warning hat you must not name the same camera twice in AVD Manager. So selecting webcam for front AND back would run afoul that rule.