1. Download our Official Android App: Forums for Android!

Open camera for x seconds and then take picture

Discussion in 'Android Apps & Games' started by jhoblik, Aug 21, 2011.

  1. jhoblik

    jhoblik Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    1
    Joined:
    Jul 21, 2011

    Jul 21, 2011
    1
    0
    5
    Hi,
    I would like to open camera preview for example for 5 seconds and then take picture without user interaction.
    Here is my code, it takes picture before camera preview show up. Do you know how to fix it.

    public class CameraView extends Activity implements SurfaceHolder.Callback,
    OnClickListener {
    TextView timeDisplay;
    static final int FOTO_MODE = 0;
    private static final String TAG = "CameraTest";
    Camera mCamera;
    boolean mPreviewRunning = false;
    private Context mContext = this;

    public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    Log.e(TAG, "onCreate");

    Bundle extras = getIntent().getExtras();

    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
    WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);
    mSurfaceView = (SurfaceView) findViewById(R.id.surface_camera);
    mSurfaceView.setOnClickListener(this);
    mSurfaceHolder = mSurfaceView.getHolder();
    mSurfaceHolder.addCallback(this);
    mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    }

    protected void onResume() {
    Log.e(TAG, "onResume");
    super.onResume();
    }

    public void surfaceCreated(SurfaceHolder holder) {
    Log.e(TAG, "surfaceCreated");
    mCamera = Camera.open();

    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    Log.e(TAG, "surfaceChanged");


    if (mPreviewRunning) {
    mCamera.stopPreview();
    }

    Camera.Parameters p = mCamera.getParameters();
    p.setPreviewSize(w, h);
    mCamera.setParameters(p);
    try {
    mCamera.setPreviewDisplay(holder);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    mCamera.startPreview();
    mPreviewRunning = true;
    mCamera.takePicture(null, mPictureCallback, mPictureCallback);
    }
     

    Advertisement

Share This Page

Loading...