The camera function is called in the background service, and the camera function does not require preview, so the corresponding function is not added during configuration. This problem occurred and the camera function cannot be used normally.
def camerax_version = "1.2.1" // The following line is optional, as the core library is included indirectly by camera-camera2 implementation "androidx.camera:camera-core:${camerax_version}" implementation "androidx.camera:camera-camera2:${camerax_version}" // If you want to additionally use the CameraX Lifecycle library implementation "androidx.camera:camera-lifecycle:${camerax_version}" // If you want to additionally use the CameraX VideoCapture library implementation "androidx.camera:camera-video:${camerax_version}" // If you want to additionally use the CameraX View class implementation "androidx.camera:camera-view:${camerax_version}" // If you want to additionally use the CameraX Extensions library implementation "androidx.camera:camera-extensions:${camerax_version}"
lifeCycleOwner = ServiceLifeCycleOwner()
val cameraProviderFuture = ProcessCameraProvider.getInstance(this)
cameraProviderFuture.addListener({
// Used to bind the lifecycle of cameras to the lifecycle owner
val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
imageCapture = ImageCapture.Builder().build()
// Select back camera as a default
// val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
val cameraSelector = CameraSelector.DEFAULT_FRONT_CAMERA
try {
// Unbind use cases before rebinding
cameraProvider.unbindAll()
cameraProvider.bindToLifecycle(
lifeCycleOwner!!, cameraSelector, imageCapture
)
lifeCycleOwner?.start()
} catch (exc: Exception) {
exc.printStackTrace()
}
}, ContextCompat.getMainExecutor(this))
05-09 17:09:25.044 23749 18816 W CameraX : java.lang.IllegalArgumentException: No display can be found from the input display manager!
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.DisplayInfoManager.getMaxSizeDisplay(DisplayInfoManager.java:102)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.DisplayInfoManager.calculatePreviewSize(DisplayInfoManager.java:126)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.DisplayInfoManager.getPreviewSize(DisplayInfoManager.java:119)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.SupportedSurfaceCombination.generateSurfaceSizeDefinition(SupportedSurfaceCombination.java:788)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.SupportedSurfaceCombination.(SupportedSurfaceCombination.java:144)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.init(Camera2DeviceSurfaceManager.java:107)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.(Camera2DeviceSurfaceManager.java:95)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.internal.Camera2DeviceSurfaceManager.(Camera2DeviceSurfaceManager.java:67)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.Camera2Config.lambda$defaultConfig$0(Camera2Config.java:54)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.camera2.Camera2Config$$ExternalSyntheticLambda1.newInstance(Unknown Source:0)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.core.CameraX.lambda$initAndRetryRecursively$2$androidx-camera-core-CameraX(CameraX.java:321)
05-09 17:09:25.044 23749 18816 W CameraX : at androidx.camera.core.CameraX$$ExternalSyntheticLambda3.run(Unknown Source:10)
05-09 17:09:25.044 23749 18816 W CameraX : at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
05-09 17:09:25.044 23749 18816 W CameraX : at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
05-09 17:09:25.044 23749 18816 W CameraX : at java.lang.Thread.run(Thread.java:923)
I’d like to know how to fix this problem since devices of the same type and system don’t have this problem.
jinyi li is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.