使用 camera2 与弃用的 Camera - 最佳做法是什么?

Use of camera2 versus deprecated Camera - what is best practice?

我正在编写一个应用程序,其中相机是必不可少的功能。对此我想100%确定以下几个方面:

  1. 如果我使用已弃用的相机:应用程序是否仍会在所有 API 上 运行 现在?
  2. 如果 1) 是:这个应用在什么时间点不会 运行 在所有 API 上(我的应用程序应至少覆盖 API 17)?
  3. 我在哪里可以找到关于 2) 的最新官方信息,即计划内容和时间?
  4. 说,我现在已经使用新的 camera2,我的理解是该应用程序会 不是 运行 任何低于 21 的 API - 正确吗?
  5. 根据目前获得的信息,我的工作假设是:现在仍然使用已弃用的相机。但请继续关注 API 的市场份额并尽快开始学习 camera2,以便准备在未来 2-3 年内将应用程序切换到 camera2。你同意吗?

无论如何,在几乎所有目标设备上使用设备的摄像头并使其 运行 已经够棘手了(至于现在我很高兴掌握了 "old" 摄像头.. .).因此,我很想确定以上几点。非常感谢您的回答。

If I use the deprecated camera: will the app still run on all APIs now?

是的。

At what point in time this app will not run anymore on all APIs (my app shall cover minimum API 17) ?

建造一个时间机器,进入未来,找出答案,并让我们其他人知道。

IOW,我们无法预测 Google 是否以及何时可能完全停止此 API。话虽这么说,他们几乎从不停止 APIs。

Where can I find updated official information about 2), i.e. what is planned and by when?

通过 Google 找到一份工作,或者使用上述时间机器选项。 Google没有提前公布计划的习惯,他们的时光机不出租

(虽然 Elon Musk 可能有一辆配备 Mr. Fusion 的特斯拉,所以你可以联系他...)

I would use the new camera2 already now, my understanding is that the app would not run on any API below 21 - correct?

正确。

NOW still use the the deprecated Camera. But Keep watching market shares of APIs and start learning camera2 soon, in order to be ready to switch the app to camera2 within the next 2-3 years. Do you agree?

不,我会在您下次报价后澄清原因。

the use of a device's camera and making it run on virtually all targeted devices is tricky enough

部分原因在于设备制造商的相机实现可能被慷慨地描述为 "quirky"。

坚持使用旧相机 API 的唯一问题是我预计 API 的质量控制会稳步下降。设备制造商在相机方面拥有的有限资源将主要用于新的 API。

因此,我的建议是同时使用 API:尽可能使用 camera2 并在需要时回退到原始 API。诚然,这需要做更多的工作。如果你不适合做这项工作,那么你别无选择,只能坚持使用原来的相机 API 直到你准备好让你的 minSdkVersion 成为 21+.

Google 刚刚发布了 CameraX,一个 API 包装相机和 camera2。这项新支持 API 试图消除每个制造商为我们的体验添加的怪癖。

查看:https://developer.android.com/training/camerax