I created my own application for the camera. And when I press the button, she takes a photo and saves it in galari. I want to take a picture without previewing and without clicking a button.
My main activity class.
package themiya.camera.android; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import android.app.Activity; import android.content.Context; import android.content.pm.PackageManager; import android.hardware.Camera; import android.hardware.Camera.PictureCallback; import android.net.Uri; import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.view.View; import android.widget.Button; import android.widget.FrameLayout; import android.widget.Toast; public class CameraActivity extends Activity { private Camera mCamera; private CameraPreview mPreview; public static final int MEDIA_TYPE_IMAGE = 1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button captureButton = (Button) findViewById(R.id.button_capture); System.out.println("Starting!");
And a preview class.
package themiya.camera.android; import android.content.Context; import android.hardware.Camera; import android.view.SurfaceHolder; import android.view.SurfaceView; public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback{ private SurfaceHolder mHolder; private Camera mCamera; public CameraPreview(Context context,Camera camera) { super(context); mCamera = camera;
In an activity class, the on click method is as follows.
captureButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) {
And when I delete this part of the listener and put only
mCamera.takePicture(null, null, mPicture);
application crashes. I think this may be due to the delay that the application takes to open the camera. Therefore, the code tries to get a photo before opening the camera. Also wait (10000); not working for me.
And also I want to take a picture without preview. To my knowledge, I have to change the preview class to do this. But I donβt know how to do it right.
Can anyone help me with this asp.
source share