Search code examples
androidcamerapreview

Android - Camera, save pic every 20 seconds


If it possible to retrieve camera pic in background and save the pic every 30 seconds? Does anyone have example? Thanks.


Solution

  • What you are asking about is partially possible. I'm going to break your question into a couple parts to answer:

    1. Is it possible to retrieve a camera pic in the background? NO
    2. Is it possible to save a pic every 30 seconds? YES

    Basically, you can only open the camera and obtain preview frames to save if the Camera object is attached to a valid SurfaceHolder to draw with. While this doesn't technically mean that the surface has to be VISIBLE (i.e. you can draw camera preview frames into a SurfaceView that is invisible, I believe), it does mean that there must be a valid surface in a running foreground Activity.

    If you can live with this, though, you can easily write an application the auto-captures the preview frames every so often with the combination of the Camera.PreviewCallback and a Handler calling postDelayed() to tell the application when it's time to capture the next frame. For an example, I'm going to point you at the SDK Guide for Camera, since they provide all the information necessary to access a Camera instance and register for previews.

    HTH