Search code examples
androidionic-frameworkandroid-cameracordova-pluginsandroid-camera2

Is it possible to use Android's old camera and new camera2 API concurrently?


In my ionic3 project I am using the cordova-plugin-camera-preview plugin for accessing the camera which is based on the old camera API. But I would like to focus manually which is a feature possible only through the new camera2 API. So far I couldn't find a Cordova plugin written for the new camera2 API.

I was wondering if it is possible to continue using the existing plugin and possibly write another small Cordova plugin (or maybe a function in the existing plugin) using the camera2 API only for setting the focus manually? That way, I won't have to re-write the whole plugin again.

In other words, can I capture a photo using camera API with a focus set using camera2 API?


Solution

  • No, the APIs don't have any way to hand off a camera device between them. Once you open a camera with the old API, you're stuck with it until you close it and reopen it with camera2, or vice versa. And that close/reopen takes a second or so, and doesn't generally preserve camera settings.

    The operating models of the two APIs aren't really compatible enough to make this kind of thing feasible, as nice as it would be otherwise. Far too many gotcha corner cases would pop up.