I am using camera2
api, based on Google example.
Work fine on my device, but doesn't work on emulator(and maybe some other devices).
The reason CaptureResult.CONTROL_AF_STATE
is in state CaptureResult.CONTROL_AF_STATE_INACTIVE
.
Part of the code(identical to Google example)
case STATE_WAITING_LOCK: {
Integer afState = result.get(CaptureResult.CONTROL_AF_STATE);
if (afState == null) {
captureStillPicture();
} else if (CaptureResult.CONTROL_AF_STATE_FOCUSED_LOCKED == afState ||
CaptureResult.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED == afState) {
// CONTROL_AE_STATE can be null on some devices
Integer aeState = result.get(CaptureResult.CONTROL_AE_STATE);
if (aeState == null ||
aeState == CaptureResult.CONTROL_AE_STATE_CONVERGED) {
mState = STATE_PICTURE_TAKEN;
captureStillPicture();
} else {
runPrecaptureSequence();
}
}
break;
}
As we can see if the state is INACTIVE
nothing happen.
I am afraid that this can happen not only on emulator, so my question is not safe to take picture even if AUTO FOCUS STATE INACTIVE
? and what to do about that?
In emulator, auto focus mode might not be available.
So in addition to the null check, try changing the condition to the inactive state as well.
if (afState == null || CaptureResult.CONTROL_AF_STATE_INACTIVE == afState) {
captureStillPicture();
}