Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Camera to take picture in a background Service on Android? [duplicate]

I'm developing a Service, running in background, that uploads succesfully images and data to the web.

Now I want to upload an image taken by the Camera.

Is it possible to use the camera in a background service without preview on Android 2.2?

I found various contrastants answers on web...

How can I do it?

like image 535
Lork Avatar asked Sep 13 '11 08:09

Lork


People also ask

Can Android use background camera?

On Android 9 (API level 28) and later, apps running in the background cannot access the camera . Therefore, you should use the camera either when your app is in the foreground or as part of a foreground service . For foreground service please check here .

How do I take multiple pictures with my Android phone camera?

For Android users -- Open the camera app, press and keep holding the shutter button. -- This automatically activates the Burst Mode and clicks multiple photos until you release the button.

How do I take pictures of my Android phone automatically?

Focus and click on the Capture button on the camera app. Once you click on the Capture button, the timer will do a countdown, which you will be able to see on your device's screen. Once the countdown is up, your camera will take a picture, which will then be automatically saved in your device's gallery.


2 Answers

You can take pictures without preview with an dummy view.

like:

SurfaceView view = new SurfaceView(this);
c.setPreviewDisplay(view.getHolder());
c.startPreview();
c.takePicture(shutterCallback, rawPictureCallback, jpegPictureCallback);
like image 193
Michele Avatar answered Oct 23 '22 15:10

Michele


It's not possible without the preview / surface view.

like image 34
Mathias Conradt Avatar answered Oct 23 '22 13:10

Mathias Conradt