Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock a picture in Android Emulator Camera?

Is there a way to set a static picture as the photo been taken by the emulator camera? I would like to test ir with zxing barcode reader on emulator.

like image 567
JoaoGalli Avatar asked May 29 '11 02:05

JoaoGalli


People also ask

Can you use camera on Android Emulator?

So yes, the emulator can now use your webcam.

How do I use the camera on NOX emulator?

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.


1 Answers

If you are running the emulator on linux you can create a mock webcam showing an image (e.g. QRcode) with v4l2loopback and gstreamer.

Install v4l2loopback:

$ wget https://github.com/umlaeute/v4l2loopback/archive/master.zip $ unzip master.zip $ cd v4l2loopback $ make $ sudo make install 

Check how many cameras you already have (I only had /dev/video0) and init the next one:

$ sudo modprobe v4l2loopback video_nr=1 card_label="mockCam" 

Stream an image (for example a QR from googlecharts) to the mockCam. This requres :

$ wget "https://chart.googleapis.com/chart?chs=600x340&cht=qr&chl=testing" -O qr.png $ gst-launch-0.10 filesrc location=qr.png ! pngdec ! freeze ! v4l2sink device=/dev/video1 

You can check if your mock camera is picked up by the emulator:

$ ./emulator -avd yourAVD -webcam-list 

If so, you can start the emulator with the mock webcam:

$ ./emulator -avd yourAVD -camera-back webcam1 

You can also change the AVD setting to webcam1. Hope this helps.

like image 181
Martin Klomp Avatar answered Oct 08 '22 11:10

Martin Klomp