All the examples of invoking the Android camera with androidx.camera.core.ImageCapture are in Kotlin or are really out of date, and I am getting weird compilation errors with Java.
androidx.camera.core.ImageCapture imageCapture;
...
protected void onCreate(Bundle savedInstanceState) {
...
imageCapture = new ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.build();
...
}
public void snapQRCode(View view) {
imageCapture.takePicture(executor, new androidx.camera.core.ImageCapture.OnImageCapturedCallback(){
void onCaptureSuccess(ImageProxy image){}
void onError(ImageCaptureException exception) {}
}
);
}
This throws a compile error:
error: onCaptureSuccess(ImageProxy) in anonymous xyz.MainActivity$1 cannot override onCaptureSuccess(ImageProxy) in OnImageCapturedCallback void onCaptureSuccess(ImageProxy image){}
I am confused because ImageCapture.OnImageCapturedCallback is abstract. I shouldn't be overriding at all. I am pretty sure I have the camera configured correctly, but if someone could explain this error, and perhaps provide a few lines of (Java) code that snaps the picture and returns the image, that would be much appreciated.
Here are the libraries I am using in app/build.gradle:
def cameraxVersion = "1.0.0-beta03"
implementation "androidx.camera:camera-core:${cameraxVersion}"
implementation "androidx.camera:camera-camera2:${cameraxVersion}"
implementation "androidx.camera:camera-lifecycle:${cameraxVersion}"