0

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.

Biratus
  • 23
  • 1
  • 1
  • 8
  • Do u want to take screen shot of various screens from ur service??? – DJphy Jun 01 '15 at 11:40
  • I want to take picture with the front camera – Biratus Jun 01 '15 at 11:55
  • 1
    Take a look here http://stackoverflow.com/questions/14277981/android-is-it-possible-to-take-a-picture-with-the-camera-from-a-service-with-no – Heisenberg Jun 01 '15 at 12:00
  • As Heisenberg noticed, you can't take a picture without an active camera preview and by that I mean visible on screen. It's implemented that way to prevent hidden camera apps. – Edson Menegatti Jun 01 '15 at 14:09

0 Answers0