how to connect and open USB camera on Android OS 9?-ThrowExceptions

Exception or error:

I’m trying open preview which is USB camera connecting with Android OS 9.

At first, I tried using ‘Camera2’ API but
‘CameraManager.cameraIds’ return only device’s cameraIds.
I know I could find that USB device by UsbManager.getDeviceList.

But, I don’t know that device open as a camera.

If you have answer by Camera2, it’s a best solution. but if not by Camera2, I’m welcome.

Thank you

How to solve:

When you insert a USB camera, There are few things that you need to check first.

1) Is your camera getting power from USB port?(For this to happen your USB port should have USB-OTG support- USB port can act both as target and host, Check whether the lights on camera(if any) are glowing or not?)

2) Is node getting created in /dev directory?(Only in case the kernel has v4l2 and UVC support enabled,node will be created). If node is getting created, now you have access to the real hardware that is USB camera and your job is going to be easy from here on. to check do ls -l /dev/v* inside the android file system and check whether video0 or video1 is being created.

4) If node is created, you need to write a firmware(UVC) and acquire a frame from the real hardware. It(UVC) supports different ioctl calls that talk to the v4l2 layer in the kernel and will fetch you the frames.

These frames would be mostly of format YUYV422 or YUYV420 format.

Once you receive the frames, convert into RGB or Jpeg (Android has support to convert ) and display on the canvas or imageview whichever you like.

For recording you might have to use fmpeg for encoding. This will convert the images into video.

Leave a Reply

Your email address will not be published. Required fields are marked *