[英]My app doesn’t recognize the usb external camera (front and back camera are recognized, even i can use them), I’m using the Android Camera2 API
我的应用无法识别 usb 外置摄像头(前后摄像头都可以识别,即使我可以使用它们),我正在使用 Android Camera2 API。 我没有使用它(ICameraProvider 接口),因为我真的不知道如何使用它。 我已经在motorola one action (Android 10.0) 和 LG 3 stylus (Android 7.0) 上对其进行了测试。
第一个问题:我需要使用ICameraProvider接口吗,怎么用? https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/camera/provider/2.4/ICameraProvider.hal
第二个问题:“外部 USB 相机”Android 文档的实施部分是针对开发人员的,还是我应该做任何步骤? https://source.android.com/devices/camera/external-usb-cameras
第三个问题:我应该根我的手机吗?
我的一些代码(此代码仅识别前后摄像头,但不识别 usb 摄像头):
package com.example.camera10;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.content.Intent;
import android.hardware.camera2.params.StreamConfigurationMap;
import android.hardware.usb.UsbManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCaptureSession;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraDevice;
import android.hardware.camera2.CameraManager;
import java.util.HashMap;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public class IdCameras extends AppCompatActivity {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_id_cameras);
Intent intent = getIntent();
CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
try {
String[] idList = manager.getCameraIdList();
Log.d("Available Cameras", String.valueOf(idList.length));
TextView textView = findViewById(R.id.textView);
textView.setText(String.valueOf(idList.length));
int maxCameraCnt = idList.length;
for (int index = 0; index < maxCameraCnt; index++) {
String cameraId = manager.getCameraIdList()[index];
Log.d("Camera", cameraId);
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId);
StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
}
} catch (CameraAccessException e) {
e.printStackTrace();
}
// Capture the layout's TextView and set the string as its text
}
}
Android 手机不需要支持外部网络摄像头。 您找到的说明适用于制造商,以帮助他们使网络摄像头显示在摄像头2 API 中。
如果制造商没有决定支持网络摄像头,您的选择是使用 USB API 并在您的应用程序中实现完整的 UVC 网络摄像头堆栈(有可用的库)。 或者,如果您只关心特定的 Android 设备,并且可以为其制作自定义图像,则可以按照找到的说明在设备上启用网络摄像头支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.