Access both back and front cameras simultaneously

What I'm trying to achieve: access both front and back cameras at the same time.

What I've researched: I know android camera API doesn't give support for using multiple instances of the Camera and you have to release a camera before using the other one. I've read tens of questions about this, I know on some devices it's possible (like Samsung S4, or other new devices from them). I've also found out that it's possible to have access to both of them in Android KitKat on SOME devices. I also know that on api >= 21, using the camera2 API, it's possible to access both of them at the same time because it's thread safe.

What I've got so far: implementation for accessing the cameras one at the time in order to provide a picture-in-picture.

I know it's not possible to implement dual simultaneously camera on every device, I just want a way to make it available to some devices.

How can I test to see if the device is capable of accessing both of them?

I've also searched for a library that can allow me such thing, but I didn't find anything. Is there such a library?

I would like to make this feature available for as many devices as possible, and for the others, I'll leave the current state (one by one) of the feature.

Can anyone please help me, at least with some pieces of advice?

Thanks !


The Android camera APIs generally allow multiple cameras to be used at the same time, but most devices do not have enough hardware resources to support that in practice - for example, there's often only one camera image processor shared by both cameras.

There's no query that's included in the Android APIs that'll tell you up front if you can use multiple cameras at the same time.

The only way to tell is to try to open a second camera when you already have one open. If you can open the second camera, then you can do picture-in-picture, etc. If you get an exception trying to open the second camera, then that particular device doesn't support having both cameras open.


It is possible using the Android Camera2 API, but as indicated above most devices don't have hardware support. If you have a Nexus 5X, Nexus 6, or Nexus 6P it will work and you can test with this BothCameras app. I've implemented blitting to allow video recording as well (in addition to still pictures) using the hardware h264 encoder.