Reputation: 546
There is a problem with custom camera app and Samsung Galaxy S4 phone. Sometimes, when the app takes picture, the S4 phone can take multiple pictures at once. It happens occasionally same code working for other devices just fine. Here is the code that takes picture:
Parameters params = camera.getParameters();
params.setRotation(rotation);
camera.setParameters(params);
camera.autoFocus(new Camera.AutoFocusCallback() {
@Override
public void onAutoFocus(boolean success, Camera camera) {
camera.takePicture(shutterCallback, null, PreviewCallback.this);
}
});
@Override
public void onPictureTaken(byte[] data, Camera camera) {
pictureCallback.onPictureTaken(previewData, data);
camera.startPreview();
Parameters params = camera.getParameters();
params.setRotation(rotationOrig);
camera.setParameters(params);
}
Rotation is just for correct exif rotation tags.
Upvotes: 0
Views: 1360
Reputation: 57203
The contract for Camera.AutoFocusCallback.onAutoFocus does not assume that it will be triggered only once after a call to camera.autoFocus(). So, I would simply add a boolean variable, e.g.
camera.autoFocus(new Camera.AutoFocusCallback() {
boolean once = true;
@Override
public void onAutoFocus(boolean success, Camera camera) {
if (once && success) {
camera.takePicture(shutterCallback, null, PreviewCallback.this);
once = false;
}
}
});
BTW, you should check the first parameter value - if autofocus failed, you probably don't want to take the picture in the first place.
Upvotes: 3