我的应用无法识别USB外部相机即使我可以使用,也可以识别正面和背面的相机,我正在使用Android Camera2 API

问题描述

我的应用无法识别USB外部相机(即使我可以使用,也可以识别正面和背面的相机),我使用的是Android Camera2 API。我没有使用它(ICameraProvider界面),因为我真的不知道如何使用它。 我已经在Motorola One Action(Android 10.0)和LG 3手写笔(Android 7.0)上进行了测试。

第一个问题: 我是否需要使用ICameraProvider接口,该如何使用? https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/camera/provider/2.4/ICameraProvider.hal

第二个问题: Android文档“外部USB相机”的“实现”部分面向开发人员,还是应该执行任何步骤? 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

    }
}

enter image description here

解决方法

Android手机支持外部网络摄像头不是强制性的。找到的说明适用于制造商,以帮助他们使网络摄像头能够显示在camera2 API中。

如果制造商未决定支持网络摄像头,则可以选择使用USB API,并在应用程序中实现完整的UVC网络摄像头堆栈(有可用的库来实现)。或者,如果您只关心特定的Android设备,并且可以为其制作自定义图片,则可以按照发现的说明在设备上启用网络摄像头支持。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...