如何解决我的应用无法识别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
}
}
解决方法
Android手机支持外部网络摄像头不是强制性的。找到的说明适用于制造商,以帮助他们使网络摄像头能够显示在camera2 API中。
如果制造商未决定支持网络摄像头,则可以选择使用USB API,并在应用程序中实现完整的UVC网络摄像头堆栈(有可用的库来实现)。或者,如果您只关心特定的Android设备,并且可以为其制作自定义图片,则可以按照发现的说明在设备上启用网络摄像头支持。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。