Using Camera in the Android emulator

AndroidCameraEmulationSimulation

Android Problem Overview


I wish to simulate camera in the android emulator using the webcam. Basically I need to only take photos with the camera in the emulator (live preview is not needed i.e if it makes it any easier)

I followed the tutorial here which is the only one I could find that was close to my requirements

But many of the libraries used in that tutorial(like android.hardware.CameraDevice) are not available in present sdk and are replaced by new libraries(like android.hardware.camera).

Any help on how to do this in the present sdk(2.1 or 2.2) would be much appreciated.

Android Solutions


Solution 1 - Android

In your AVD advanced settings, you should be able to set front and back cameras to Webcam() or Emulated.

enter image description here

Solution 2 - Android

Update: ICS emulator supports camera.

Solution 3 - Android

Some elaboration, in the hope of clarifying what has already been said:

As stated above, Webcams are supported natively in the current SDK, but only on recent android versions (4.0 and higher)

Webcam detection is automatic where present. In 4.0.3, the camera defaults to the front-facing camera so a lot of applications (especially pre-2.3 applications, which can only fetch the default camera, i.e. the back-facing one) will still show you the old checkerbox-with-moving-square stand-in instead.

I think some more info is available in the following post: https://stackoverflow.com/questions/3284583/camera-on-android-eclipse-emulator/8443673#8443673

Or at least, that's the most information I've been able to find--aside from the brief, uninformative statements in the release notes for the SDK tools.

Solution 4 - Android

Update of @param's answer.

ICS emulator supports camera.

I found Simple Android Photo Capture, which supports webcam in android emulator.

Solution 5 - Android

If you're working with command-line tools or just want to edit your config.ini file directly, you have options:

Option 1: use command-line options

emulator -help | grep cam # => shows items such as -camera-back
emulator -help-camera-back # => show supported values for this option
emulator -avd $MY_AVD -camera-back virtualscene # Example invocation

If you want to use your actual camera instead of a mock, the option's value will be webcam${N}. How do you know what ${N} should be? emulator -webcam-list lists and describes the cameras available on your computer.

Option 2: edit the config file

Using the legal values we learnt above, edit the file ~/.android/avd/${MY_AVD}/config.ini and add a line (I'll use virtualscene as my value of choice):

hw.camera.back = virtualscene

Solution 6 - Android

Does not seem like it, but android recognises a webcam as a device. Every time I run the emulator my webcam's active light comes on.

Solution 7 - Android

There is an updated version of Tom Gibara's tutorial. You can change the Webcam Broadcaster to work with JMyron instead of the old JMF.

The new emulator (sdk r15) manage webcams ; but it has some problems with integrated webcams (at least with mine's ^^)

Solution 8 - Android

The newest camera2 apis work fine w/ an emulator that has camera support enabled.

Example for using the newer API:

https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/AutoFitTextureView.java

Solution 9 - Android

Just in case you just need to show a picture in response to a camera request, there is image-to-camera.

Just download, build, install, copy an image of your choice to the device, and you can select it via the app, which is an alternative to the built-in camera.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPrimal PappachanView Question on Stackoverflow
Solution 1 - AndroidAdam JohnsView Answer on Stackoverflow
Solution 2 - AndroidParamvir SinghView Answer on Stackoverflow
Solution 3 - AndroidCurious LemmingView Answer on Stackoverflow
Solution 4 - AndroidAhsanView Answer on Stackoverflow
Solution 5 - AndroidJellicleCatView Answer on Stackoverflow
Solution 6 - AndroidKeagan LaddsView Answer on Stackoverflow
Solution 7 - AndroidSolostaran14View Answer on Stackoverflow
Solution 8 - AndroidAjaxView Answer on Stackoverflow
Solution 9 - Androidserv-incView Answer on Stackoverflow