jun jiang
unread,May 8, 2025, 10:06:39 PMMay 8Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Android CameraX Discussion Group
Hi, experts of Camerax!
I'm a developer of a camera APP with camerax. Because I need to take photos in macro mode to get more detail features of the subject, I need to choose a specific physical camera to take photo, e.g. the telephoto camera.
I'm using a Sumsung Galaxy S23 Ultra model to test. There are four physical lens in S23, which are the ultra-wide、wide、telephoto(3x)、telephoto(10x) respectively.
I used cameraManager.getCameraIdList() to get the logical cameras. The logical camera with ID "0" is composed of 4 physical cameras(IDs are 2,5,6,7).
I have tried two ways to set the specific physical camera, but still got failed. There was no effect, the defalt camera was always used.
Method 1:
I used the setPhysicalCameraId() of the CameraSelector.Builder() to set the specific physical camera(e.g. the physical camera "5"). The api was added in camerax 1.4.0. The camerax version I used is v1.4.2.
for (String id : logicCameraIds) {
CameraCharacteristics cameraCharacteristics = cameraManager.getCameraCharacteristics(id);
Set<String> physicalCameraIds = cameraCharacteristics.getPhysicalCameraIds();
if (physicalCameraIds.contains(targetPhysicalCameraId)) {
targetLogicalCameraId = id;
return new CameraSelector.Builder()
.addCameraFilter(cameraInfos -> {
return cameraInfos.stream().filter(camInfo -> {
String thisCamId = Camera2CameraInfo.from(camInfo).getCameraId();
return thisCamId.equals(id);
}).collect(Collectors.toList());
})
.setPhysicalCameraId(targetPhysicalCameraId)
.build();
}
else{
continue;
}
}
Method 2:
I used the Camera2Interop.Extender.setPhysicalCameraId to set the specific physical camera. Firstly, I got the cameraselector with the logical camera "0", then set the specific physical camera "5" with the Camera2Interop.Extender.setPhysicalCameraId.
Preview.Builder previewBuilder = new Preview.Builder();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
Camera2Interop.Extender previewExtender = new Camera2Interop.Extender(previewBuilder).setPhysicalCameraId(targetPhysicalCamera);
}
Preview preview = previewBuilder
//.setPreviewStabilizationEnabled(true)
.build();
preview.setSurfaceProvider(viewBinding.viewFinder.getSurfaceProvider());
ImageCapture.Builder imageCaptureBuilder = new ImageCapture.Builder();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
Camera2Interop.Extender imageCaptureExtender = new Camera2Interop.Extender(imageCaptureBuilder).setPhysicalCameraId(targetPhysicalCamera);
}
imageCapture = imageCaptureBuilder.build();
Unfortunately, there was no effect with the two methods above, the default camera was used and it can't switch to the specific physical camera.
Is there anyone could tell me have to switch to specific physical camera? This function is very common for users, so I suggest to consider adding the function to the camerax.