简体   繁体   中英

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

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. I'm not using it (ICameraProvider interface) because I don't really know how to use it. I've tested it on motorola one action (Android 10.0) and LG 3 stylus (Android 7.0).

First question: Do I need to use the ICameraProvider interface, how could I use it? https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/master/camera/provider/2.4/ICameraProvider.hal

Second question: The Implementation section of the “External USB Cameras” Android documentation is for developers or should I do any steps? https://source.android.com/devices/camera/external-usb-cameras

Third questino: Should I root my phone?

Some of my code (This code only recognizes the front and back camera but not the usb camera):

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

    }
}

在此处输入图像描述

It's not mandatory for Android phones to support external webcams. The instructions you found are for the manufacturer, to help them enable webcams to show up in the camera2 API.

If the manufacturer did not decide to support webcams, your options are to use the USB APIs and implement the full UVC webcamera stack in your app (there are libraries available that do that). Or if you only care about a particular Android device, and you can make custom images for it, you can follow those instructions you found to enable webcam support on the device.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM