Tell me, who knows, I can not figure out what's wrong. When you press the camera button, an event occurs:

private void takePicture() { camera.takePicture(shutterCallback, null, null, jpegCallback); shutterCallback = new ShutterCallback() { public void onShutter() { camera.startPreview(); } }; // запись файла jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] data, Camera camera) { if (data != null) { mydata = data; done(); // сохранение изображения camera.startPreview(); } } }; } 

An image appears on the screen, but it is not saved and startPreview does not work. Only after the second button press, the image is saved and the prewiew works prewiew .

    1 answer 1

    You pass callbacks before you initialize them. And the second time they are already initialized, so the second time it works as it should.

    Correctly:

     private void takePicture() { if (shutterCallback == null) { shutterCallback = new ShutterCallback() { public void onShutter() { camera.startPreview(); } }; } // запись файла if (jpegCallback == null) { jpegCallback = new PictureCallback() { public void onPictureTaken(byte[] data, Camera camera) { if (data != null) { mydata = data; done(); // сохранение изображения camera.startPreview(); } } }; } camera.takePicture(shutterCallback, null, null, jpegCallback); 

    }