I have created my own camera application. And when I click the button it takes the picture and saves it in the galary. What I want to do is to take the picture without a preview
its simple create another method with a timer variable with 10000 delay which finishes the activity of previewing then you will be done. The logic is that these method will run 5secs after timer 1 activity is done.
Ok I found a answer to take the picture automatically. Adding as a comment for the use of others.
final Timer t = new Timer();
t.schedule(new TimerTask() {
@Override
public void run() {
mCamera.takePicture(null, null, mPicture); t.cancel();
}
},5000);
the trick is to give the Camera Class a SurfaceView which is not part of the view hierarchy. The following code is from one of my apps where i used this technique to display my own
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
protected void onPause() {
super.onPause();
if (mCamera != null) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
}
@Override
protected void onResume() {
super.onResume();
mCamera = Camera.open();
startPreview();
}
private void startPreview() {
if (mCamera != null) {
mCamera.stopPreview();
try {
mCamera.setPreviewDisplay(new SurfaceView(this).getHolder());
} catch (IOException e) {
e.printStackTrace();
}
mCamera.setPreviewCallbackWithBuffer(this);
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(IMAGE_W, IMAGE_H);
mCamera.setParameters(parameters);
PixelFormat p = new PixelFormat();
PixelFormat.getPixelFormatInfo(parameters.getPreviewFormat(), p);
int bufSize = (IMAGE_W * IMAGE_H * p.bitsPerPixel) / 8;
mCamera.addCallbackBuffer(new byte[bufSize]);
mCamera.startPreview();
}
}
public void onPreviewFrame(final byte[] data, Camera camera) {
if (mCamera == null) {
return;
}
mCamera.addCallbackBuffer(data);
}
}