Android Camera2 Api - OnImageAvailable Is Not Invoked After Session.capture
Solution 1:
It'd be helpful if you included full logcat output from the failing device, but I suspect the problem is this:
ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
You're creating a local ImageReader object, and not saving it for further use. You do get a Surface from it, but a Surface is much like a weak pointer; it will not keep the ImageReader from getting GC'd if nothing references it (see the note in the developer references)
So I suspect if you just create a class member mReader variable, and store reader in that, everything will work OK.
It may be working on the Moto phone due to differences in the GC algorithm; the runtime just hadn't gotten around to clearing out the reader object quite yet, so it has time to invoke the callback.
Solution 2:
Override onConfigureFailed()
like this:
@Override
public void onConfigureFailed(CameraCaptureSession session) {
ImageReader mReader = ImageReader.newInstance(640, 480, ImageFormat.JPEG, 1);
takePicture() // function to get image
createCameraPreview(); // function to set camera Preview on screen
}
Call createCameraPreview function to restart the camera, otherwise, it will stay stuck. You can change the ImageReader with new values
ImageReader mReader = ImageReader.newInstance(640, 480, ImageFormat.JPEG, 1);
And call the takePicture()
function again so that user don't have to click again to capture image.
Post a Comment for "Android Camera2 Api - OnImageAvailable Is Not Invoked After Session.capture"