检测所有安卓摄像头。

3

我有一个使用Camera2 API获取相机预览的应用程序。 我想在我的手机镜头之间进行选择。 在我的代码中,我正在使用以下代码:

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE);
String[] ids = manager.getCameraIdList();

当我使用具有2个前置摄像头(常规和广角)和3个后置摄像头的Galaxy S10时,从管理器中只返回4个标识符。
0- regular rear
1- regular front
2- wide rear
3- wide front

为什么我不能使用3个后置摄像头?

我所有拥有超过1个后置摄像头的手机都出现了这个问题。

我如何才能使用所有的后置摄像头?

提前感谢。

2个回答

2
根据文档,您只能获取逻辑摄像头。
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.

要获取物理相机,请使用以下内容:

enter image description here enter image description here enter image description here

参考资料:

https://source.android.com/devices/camera/multi-camera

Camera2在Android API 29中用两个物理流替换一个逻辑流


0

我发现在某些设备上,manager.getCameraIdList(); 并不能返回所有的相机。你可以尝试使用 cameraManager.getCameraCharacteristics(cameraId); 获取相机特性,其中 cameraId 是预定义的可能相机 ID 列表中的一些 ID,类似于这样: String[] possibleCameraIDs = {"0", "1", "2", "3", "4", "5", "6", "7", "8"};


当在程序中添加不是由“manager.getCameraIdList()”给出的镜头时,它会立即崩溃。 - Finci

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接