-1

Is there any official android library to access external USB camera in android?

I have gone through all the android/camera-samples. The issue is external USB camera can not be detected/listed in the below code.

val cameraIds2 = cameraManager.cameraIdList
cameraIds2.forEach {
    println("cameraId =  $it")
}

I also checked the other libraries like saki4510t/UVCCamera and jiangdongguo/AndroidUSBCamera. But they do not work or outdated. This S.O. question is also outdated.

Android official document External USB Cameras does not provide proper way to implement it in Kotlin or Java.

I can't find the latest document related this.

Rumit Patel
  • 8,830
  • 18
  • 51
  • 70
  • FYI: The Android Compatibility Definition Document state that External USB Camera is a 'MAY': [7.5.3. External Camera](https://source.android.com/docs/compatibility/13/android-13-cdd#753_external_camera) so only at the option of the ODM. To my knowledge mobile phones are unlikely, perhaps due to biometric auth reasons, but you may have better luck with TVs running Android or a Android set top box, [Nvidia Shield](https://nvidia.custhelp.com/app/answers/detail/a_id/3684/~/what-usb-accessories-are-supported-on-shield-tv) seems to support some Logitech webcams. – Morrison Chang Aug 26 '23 at 07:24
  • @MorrisonChang , Thank for the message. I am searching for couple of weeks and couldn't find any proper solution. Though [jiangdongguo/AndroidUSBCamera](https://github.com/jiangdongguo/AndroidUSBCamera) does the work. But It does not work efficiently on lots of devices. – Rumit Patel Aug 26 '23 at 17:22
  • If you definition of a 'proper solution' is universal support for all webcams/Android devices, it is unlikely as [Linux's UVC Driver doesn't support all media payloads](http://www.ideasonboard.org/uvc/) and [UVC hardware implementations have issues](http://www.ideasonboard.org/uvc/faq/). And the Android library referenced is a user-space port/project. If you need guaranteed compatibility, I think that direct testing of hardware combinations is required. – Morrison Chang Aug 26 '23 at 20:50

1 Answers1

-2

Android devices' kernel and system image need to support an external usb camera for camera2 to find them. See this documentation from the Android AOSP for context. Please note this is for building an Android system image, not for an application.

To check if your specific device has that module, you can use ADB to look for FEATURE_CAMERA_EXTERNAL. Run adb shell pm list features | grep "android.hardware.camera.external". If it finds a line, the issue is something else, but I suspect it won't find anything.

One option would be to use the camera2 module on devices that support it (you can use the PackageManager class to check for FEATURE_CAMERA_EXTERNAL) and fallback to a userspace implementation of UVC/webcam support. Unfortunately, I was going to recommend jiangdongguo/AndroidUSBCamera, but it seems it didn't work for you. Maybe the best approach would be to file an issue on that repo's github page?

  • I have tried to check FEATURE_CAMERA_EXTERNAL on multiple devices of samsung, oneplus, vivo, motorola, etc. but they all returns false. Is there any device in your know? – Rumit Patel Aug 18 '23 at 04:08