I am trying to develop an app that would take picture when you light the screen.
I created different method to do so, and different logs. When I call the method supposed to take the picture : this is in a Service
public void photo() {
try {
cam.setPreviewDisplay(new SurfaceView(this).getHolder());
cam.startPreview();
cam.takePicture(null,null,new PhotoHandler());
Log.i("photo","end");
}catch(IOException e) {e.printStackTrace();}
}
In the logs, the "photo","end" is displayed but the logs I put in PhotoHandler are not.
I also have the "Camera" "app passed NULL Surface" log.
So I am asking you guys why is the picture not taken ? The PhotoHandler works fine, I tested it in a basic app.
Hope you'll help me !
EDIT : The camera is selected in the onCreate method of the service and gives no error.
EDIT : The problem was that my PhotoHandler wasn't called so camera.release() too. My photo() method looks like this now
public void photo() {
Camera cam=null;
try {
cam=Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
cam.setPreviewTexture(new SurfaceTexture(0));
cam.startPreview();
cam.takePicture(null,null,new PhotoHandler());
cam.stopPreview();
cam.release();
Log.i("photo","end");
}catch(IOException e) {e.printStackTrace();stopSelf();}
catch(RuntimeException re {e.printStackTrace();stopSelf();}
Now, the problem is that the takePicture method is called when the service end, must be a thread problem I assume. But what is more bothering is that the takePicture method is not always called after the service end. And when the method is called, it's called once, whereas I light the screen more than one time during the life of the service.