Search code examples
androidandroid-cameraandroid-camera2

How to check if a hidden camera id can be used to open camera? (Camera2 API)


So many devices (especially brand-Chinese ones) hide some camera ids for non-native applications.

There is still a solution to access some more cameras:

for (id in 0..511) {
    try {
        val cameraId = id.toString()
        manager.getCameraCharacteristics(cameraId)
        // found a camera, no exception
    } catch (e: Throwable) {
        // ignore
    }
}

And some users can access for example ultra wide lens camera on their Xiaomi devices with it, before they could access only main back and front cameras.

But it doesn't always work, all or part of found hidden cameras may not work on some devices when you try to open them with CameraManager.openCamera(...), there will an exception.

But if there a method to check if such camera id can be used to open camera before using CameraManager.openCamera(...) which already tries to use camera process and needs camera permission granted?


Solution

  • No, the whole reason these IDs are hidden is because they don't really follow the API rules.

    The manufacturer isn't reporting these cameras as publicly available, so they're not compliance tested by Android's compliance test suite. Nothing about their operation is guaranteed, and there are no APIs to query them, because then they'd be publicly available and have to pass these compliance tests.