Get the available cameras

33 views
Skip to first unread message

Javier Gerardo Martinez Salomon

unread,
May 17, 2021, 12:49:31 PMMay 17
to Android CameraX Discussion Group

Hi everyone,

While I was experimenting with CameraX1.0.0 I wanted to verify in advance if there was a camera that satisfies certain conditions before opening the camera and interacting with the API, I proceeded to do that with a CameraSelector that implemented a custom filter, however I can only check if there is an available camera until I call processCameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector) this works fine but requires to bind the camera selector so that the filter runs.

Then later I found about processCameraProvider.hasCamera(cameraSelector) which runs the selector and returns a boolean, I'd like to get the actual CameraInfo that gets selected beforehand, the documentation states that ProcessCameraProvider has this API ProcessCameraProvider#getavailablecamerainfos, but it's not available once I want to use it in code.

Is there a way to get the selected cameraInfo without actually binding? If not, and considering that the custom filter reflects the use cases configurations to look for sizes, would the camera returned by processCameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector) be the same we would get by calling processCameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, useCases)?
I would like to avoid binding the use cases just to know if there is a camera that might work.

Thanks

Scott Nien

unread,
May 17, 2021, 10:06:13 PMMay 17
to Javier Gerardo Martinez Salomon, Android CameraX Discussion Group
Yes, the camera instances returned are the same for 
processCameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector) and 
processCameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector, useCases). 

and for bindToLifecycle(lifecycleOwner, cameraSelector),  it won't actually open the camera and this is what we recommend for getting a camera instance before opening the camera. 

As for  ProcessCameraProvider#getavailablecamerainfos,  I believe it is added only in 1.1.0 alpha. So you can't use it in 1.0.0 stable. 





--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/c7253656-917c-4d56-b3fb-977da0064d62n%40android.com.

Javier Gerardo Martinez Salomon

unread,
May 18, 2021, 3:09:30 PMMay 18
to Android CameraX Discussion Group, Scott Nien, Android CameraX Discussion Group, Javier Gerardo Martinez Salomon
Thank you Scott,

"getAvailableCameraInfos" would be really nice to use as part of the stable release, I'll be looking forward to its stable release.

Best regards
Reply all
Reply to author
Forward
0 new messages