Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get ID of currently open camera

Tags:

android

camera

How can I get the ID of the currently open android camera from an android camera instance? I can't see it in the parameters and getCameraInfo requires the id as a parameter.

like image 894
mbdavis Avatar asked Feb 04 '14 17:02

mbdavis


People also ask

What is camera ID?

The Camera ID is a UUID that the system assigns to each camera, usually in a format that looks similar to f93369eb-e530-27b7-78ba-16978cbd3061 . The Camera ID is preferred when performing API calls. It is also used for “devices” such as virtual camera instances, encoders, I/O units, etc.

What is camera manager?

↳ android.hardware.camera2.CameraManager. A system service manager for detecting, characterizing, and connecting to CameraDevices . For more details about communicating with camera devices, read the Camera developer guide or the camera2 package documentation.


2 Answers

There isn't a way to get the id of the currently open android camera. I ended up storing the id when I opened it.

like image 92
mbdavis Avatar answered Oct 03 '22 11:10

mbdavis


It is just a number of the camera, so you loop through looking for the camera you want.

Here is a snippet to find the front-facing camera:

int cameraId = -1; int numberOfCameras = Camera.getNumberOfCameras(); for (int i = 0; i < numberOfCameras; i++) {   CameraInfo info = new CameraInfo();   Camera.getCameraInfo(i, info);   if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {     Log.d(DEBUG_TAG, "Camera found");     cameraId = i;     break;   } } 
like image 20
James Black Avatar answered Oct 03 '22 10:10

James Black