user481610
user481610

Reputation: 3270

Android Emulator not using webcam in Android Studio

As the title suggests, I'm struggling to get the emulator use the webcam on the laptop. I have enabled the front and back camera to access the webcam. Whenever the emulator boots up it asks for webcam access, which I grant. However the webcam never works when I hit the camera app on the emulator. The camera app just crashes.

Here is an image enabling the cameras:

enter image description here

Based on other posts on StackOverflow, suggesting i add the line: hw.camera=yes. Below is the config file for the avd.

avd.ini.encoding=UTF-8
AvdId=Nexus_5_API_21_x86
abi.type=x86
avd.ini.displayname=Nexus 5 API 21 x86
disk.dataPartition.size=1G
hw.accelerometer=yes
hw.audioInput=yes
hw.battery=yes
hw.camera=yes
hw.camera.back=webcam0
hw.camera.front=webcam0
hw.cpu.arch=x86
hw.dPad=no
hw.device.hash2=MD5:2fa0e16c8cceb7d385183284107c0c88
hw.device.manufacturer=Google
hw.device.name=Nexus 5
hw.gps=yes
hw.gpu.enabled=yes
hw.keyboard=yes
hw.lcd.density=480
hw.mainKeys=no
hw.ramSize=1536
hw.sdCard=yes
hw.sensors.orientation=yes
hw.sensors.proximity=yes
hw.trackBall=no
image.sysdir.1=system-images\android-21\google_apis\x86\
runtime.network.latency=none
runtime.network.speed=full
runtime.scalefactor=auto
sdcard.path=C:\Users\Roberto\.android\avd\Nexus_5_API_21_x86.avd\sdcard.img
skin.dynamic=no
skin.name=nexus_5
skin.path=C:\Program Files\Android\Android Studio1\plugins\android\lib\device-art-resources\nexus_5
snapshot.present=no
tag.display=Google APIs
tag.id=google_apis
vm.heapSize=64

At this stage I'm not sure why this is not working. Any thoughts?

Upvotes: 11

Views: 19258

Answers (4)

Tsourdi
Tsourdi

Reputation: 13

You can't choose the webcam for both front and back camera! This was the solution for me. :)

Upvotes: 0

Dimio
Dimio

Reputation: 61

I encountered a similar problem when I tried to use the host system webcam in the Android emulator. I set the webcam settings to webcam0 for the emulator, but the camera’s system application crashed with the error “Unable to access the camera”. An alternative camera application threw an "Unknown camera ID" error. This will sound ridiculous, but I just forgot to turn on the camera on my laptop using the Fn button and the camera device was not in the Windows device manager. After turning on the camera in the host system with hot keys and rebooting the emulator (with the "Cold Boot" option), the Android camera started working. Perhaps this answer will help someone as inattentive as I am.

Upvotes: 1

Rayman25
Rayman25

Reputation: 21

I just had the same problem that the webcam would not start when I started the build from the "Run" tab on Android Studio 3.01. I then opened the AVD manager. In Edit mode for the Android 5.1 device and made sure to bump the SD card to 200M, both front/back set to webcam0 for the device I was emulating. Then closed the Edit mode and just double clicked on the device - and it worked!

Upvotes: 2

Talobin
Talobin

Reputation: 187

I don't think you can set both front and back cameras to the same value. Please try to edit your config.ini file and change to this: hw.camera.back=none hw.camera.front=webcam0

Also, hw.camera=yes is not needed.

I hope that helps.

Upvotes: 8

Related Questions