11

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?

Jonas
  • 121,568
  • 97
  • 310
  • 388
Lork
  • 145
  • 1
  • 2
  • 5

2 Answers2

9

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);
Michele
  • 6,126
  • 2
  • 41
  • 45
  • 2
    This doesn't work on all devices, as noted here: http://stackoverflow.com/a/5384913/318870 – Dolan Antenucci Feb 24 '13 at 18:26
  • 1
    what is c,shutterCallback and all the variables..please provide the whole code – jyomin Nov 19 '14 at 07:05
  • 2
    This code isn't correct. I needed to add the `view` to the `WindowManager`. I also needed to add a callback to `view.getHolder()` and then in `surfaceCreated` set the preview, start the preview, and take the picture. – Sam Nov 22 '14 at 23:16
1

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

Mathias Conradt
  • 28,420
  • 21
  • 138
  • 192
  • True, but you can still use tricks such as a transparent preview or a 1x1 preview. Also, on some phones you can apparently use a dummy `SurfaceTexture` or `SurfaceView` that isn't displayed. – Sam Nov 22 '14 at 23:17
  • It works without the Surfaceview on some devices (like My note 2) but doesn't work on every device. So it's a must to use SurfaceView. – TheOnlyAnil Jun 19 '15 at 10:31