0

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}"
Mark L
  • 3
  • 2
  • 1
    I guess you are missing some modifiers, try `public void onCaptureSuccess(ImageProxy image){}` etc. – Turo Apr 20 '20 at 07:00
  • I am embarrassed to say that that worked! I was positive I had tried that in going around and around. But there it is. I did get it to work first thing this morning by going into the source code for ImageCapture.java, and seeing what they did there. Thanks! – Mark L Apr 20 '20 at 12:52
  • You're welcome. In fact I was quite sure, I tend to forget the modifiers now and then, too ;-) – Turo Apr 20 '20 at 16:02

0 Answers0