Android - How To Use Webcam in Emulator - Stack Overflow
Android - How To Use Webcam in Emulator - Stack Overflow
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
120
CameraService::connect X (pid 702) rejected (invalid cameraId 0).
sp<ICamera> CameraService::connect(
const sp<ICameraClient>& cameraClient, int cameraId) {
[...]
[...]
}
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:
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.
android
Share Improve this question edited Apr 22, 2013 at 15:42 asked Dec 23, 2012 at 17:11
Follow 1''
26.9k 32 148 202
I would suggest checking the drivers and updating them if required. – Tanuj Nayak Dec 31, 2012 at 5:48
I would suggest checking the drivers and updating them if required. – Tanuj Nayak Dec 31, 2012 at 5:48
My driver, despite being 6 years old, is supposedly up-to-date and I can't find a newer version online. I
may try changing cameras if I can find another. – 1'' Jan 1, 2013 at 4:38
UPDATE
Share Improve this answer Follow answered Jun 11, 2015 at 22:38 community wiki
nurnachman
7 You should't set the front and back camera's to the same source. – Chris River Oct 14, 2018 at 20:52
2 @ChrisRiver Why not? It shouldn't matter. – DaveTheMinion Jan 27, 2019 at 18:36
2 Cool! But how to change webcam if we have more than one? – walkmn Feb 26, 2019 at 9:54
14 It instantly crashes simulator when the camera starts. I'm on a mac. – Milind Mevada May 12, 2020 at
5:11
3 @walkmn You can use alternate cam via the CLI: cd "${ANDROID_HOME}/tools"; ./emulator -avd
$VIRTUAL_DEVICE_AVD_ID -camera-back webcam1 – steamer25 Jun 21, 2020 at 16:38
6. Once done all the above the webcam should be connected. If it doesnt then you need to
check your WebCam drivers.
Check here for more information : How to use web camera in android emulator to capture a
live image?
Share Improve this answer Follow edited May 23, 2017 at 12:34 answered Jan 2, 2013 at 10:54
Community Bot Lalith B
1 1 12.2k 6 30 47
2 I think this is an older UI for the AVD manager. I used to have a window that looked like this, but now I
can select the front and rear cameras from dedicated drop-down menus. – 1'' Jan 2, 2013 at 16:01
I use a mac so eclipse looks this way in mac osx. So the windows and menus might be different in
Microsoft windows and linux os. – Lalith B Jan 2, 2013 at 17:41
Note that you also need to choose correct API. You can choose emulation for API 10 but it won't work. I
think API 16 was the first to really support it. – Nux Jun 23, 2013 at 1:54
No the emulation is based on ADT and not on Android API. ADT supports emulation since 19 I think.
– Lalith B Jun 23, 2013 at 14:26
In the Android Studio, for the step 3 select the "Show Advanced Settings" button to display the camera
options. – eldes Sep 2, 2016 at 13:15
On macOS
6 Explanation
Adding to @nurnachman's answer above, on macOS you'll also need to grant the emulator
elevated permissions by launching it from the Terminal using sudo .
Steps
1. Use the Android Device Manager to set the Camera settings to
Webcam0
UPDATE
2. Add/Edit AVD:
~/Library/Android/sdk/emulator/emulator -list-avds
Note: Replace [Your Emulator Name] with the name of your emulator discovered in
Step 3
5. When the Emulator launches and when your app access the
Camera, accept macOS request to grant Camera permissions
Troubleshooting
Ensure Camera Permission Enabled for Terminal
If the Android Camera is still not working after launching it with elevated permissions via the
Terminal, in System Settings.app, navigate to Privacy & Security -> Camera and ensure the
Camera Permission for Terminal is enabled
Share Improve this answer Follow edited Feb 1, 2023 at 1:36 answered Jan 25, 2023 at 17:19
Brandon Minnick
14.9k 16 76 138
Unfortunately I don't see terminal in this Camera permission tab – hannes ach Jan 30, 2023 at 13:26
1 @hannesach The option won't appear in System Settings under the Camera's Permissions tab until
you've set the Android Emulator to use webcom0 , then used Terminal to launch the Android Emulator
and subsequently launch the camera on the Android Emulator. The steps to accomplish this are all
listed above. – Brandon Minnick Jan 30, 2023 at 19:54
I use MacOS Venture 13.1, I set Android Emulator to use webcom0 but I never see terminal in System
settings. That's why I'm asking – hannes ach Jan 31, 2023 at 5:47