Reputation: 118
I have a app that uses the Camera2 API to get a preview of the camera. I want to choose between the lens of my phone. In my code I am using the following code:
CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
String[] ids = manager.getCameraIdList();
When I use my galaxy s10 that have 2 front facing cameras (regular and wide) and 3 rear facing cameras I only get 4 ids back from the manager:
0- regular rear
1- regular front
2- wide rear
3- wide front
why I don't get the 3 rear macro camera.
the problems appear in all of my phones that have more then 1 camera facing back
how can I get all of the rear cameras?
tnx ahead
Upvotes: 4
Views: 5363
Reputation: 1032
As per the documentation you are getting only the logical cameras.
public String[] getCameraIdList ()
Return the list of currently connected camera devices by identifier, including cameras that may be in use by other camera API clients.
Non-removable cameras use integers starting at 0 for their identifiers, while removable cameras have a unique identifier for each individual device, even if they are the same model.
This list doesn't contain physical cameras that can only be used as part of a logical multi-camera device.
Returns
String[] The list of currently connected camera devices. This value cannot be null.
To get the physical cameras, use this
REFERENCES:
https://source.android.com/devices/camera/multi-camera
Camera2 replacing one logical stream with two physical streams in Android API 29
Upvotes: 3
Reputation: 123
I find out that on some devices not all the cameras are returned in manager.getCameraIdList();
You can try to get CameraCharacteristics using cameraManager.getCameraCharacteristics(cameraId);
with some ids from predefined list of possible camera IDs, something like this: String[] possibleCameraIDs = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};
Upvotes: 0