'CameraCaptureSession: Session 0: Exception while stopping repeating - camerax android issue

While implementing the codelab, the error showed up while running on API 32:

E/CameraCaptureSession: Session 0: Exception while stopping repeating: 
android.hardware.camera2.CameraAccessException: CAMERA_ERROR (3): cancelRequest:514: Camera 0: Error clearing streaming request: Function not implemented (-38)
    at android.hardware.camera2.CameraManager.throwAsPublicException(CameraManager.java:1271)
    at android.hardware.camera2.impl.ICameraDeviceUserWrapper.cancelRequest(ICameraDeviceUserWrapper.java:99)
    at android.hardware.camera2.impl.CameraDeviceImpl.stopRepeating(CameraDeviceImpl.java:1341)
    at android.hardware.camera2.impl.CameraCaptureSessionImpl.close(CameraCaptureSessionImpl.java:579)
    at android.hardware.camera2.impl.CameraCaptureSessionImpl$2.onDisconnected(CameraCaptureSessionImpl.java:790)
    at android.hardware.camera2.impl.CameraDeviceImpl$7.run(CameraDeviceImpl.java:267)
    at androidx.camera.core.impl.utils.executor.SequentialExecutor$1.run(SequentialExecutor.java:111)
    at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.workOnQueue(SequentialExecutor.java:231)
    at androidx.camera.core.impl.utils.executor.SequentialExecutor$QueueWorker.run(SequentialExecutor.java:173)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:920)
 Caused by: android.os.ServiceSpecificException: cancelRequest:514: Camera 0: Error clearing streaming request: Function not implemented (-38) (code 10)

Note

  1. Theres multiple similar questions but none resolved the issue. Or I do not know where to apply their solutions beacuse I do not have capture session.
  2. The code works fine on lower SDK versions such as API 25.

Code:

private fun takePhoto() {
    // Get a stable reference of the modifiable image capture use case
    val imageCapture = imageCapture ?: return

    // Create time stamped name and MediaStore entry.
    val name = SimpleDateFormat(FILENAME_FORMAT, Locale.US)
        .format(System.currentTimeMillis())
    val contentValues = ContentValues().apply {
        put(MediaStore.MediaColumns.DISPLAY_NAME, name)
        put(MediaStore.MediaColumns.MIME_TYPE, "image/jpeg")
        if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
            put(
                MediaStore.Images.Media.RELATIVE_PATH,
                "Pictures/" + resources.getString(R.string.app_name)
            )
        }
    }

      // Create output options object which contains file + metadata
   val outputOptions = ImageCapture.OutputFileOptions
         .Builder(
             contentResolver,
             MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
             contentValues
         )
         .build()


    // Set up image capture listener, which is triggered after photo has
    // been taken

        imageCapture.takePicture(
            outputOptions,
            ContextCompat.getMainExecutor(baseContext),
            object : ImageCapture.OnImageSavedCallback {
                override fun onError(exc: ImageCaptureException) {
                    Log.e(TAG, "Photo capture failed: ${exc.message}", exc)
                    Toast.makeText(
                        baseContext,
                        "Photo capture failed: ${exc.message}",
                        Toast.LENGTH_SHORT
                    ).show()
                }

                override fun
                        onImageSaved(output: ImageCapture.OutputFileResults) {
                    val msg = "Original Photo save succeeded: ${output.savedUri}"
                    Toast.makeText(baseContext, msg, Toast.LENGTH_SHORT).show()
                    Log.d(TAG, msg)
                    ///

                }
            }
        ) 

    ///
    /*imageCapture.takePicture(
        ContextCompat.getMainExecutor(this), object : ImageCapture.OnImageCapturedCallback() {
            override fun onCaptureSuccess(image: ImageProxy) {
                super.onCaptureSuccess(image)

            }

            override fun onError(exception: ImageCaptureException) {
                super.onError(exception)
            }
        })*/
    ///


}

How to solve this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source