如何使用 Android 的 camera 或 camera2 API 来支持新旧 API 版本而没有弃用说明? [英] How to use Android's camera or camera2 API to support old and new API versions without deprecation notes?

查看:26
本文介绍了如何使用 Android 的 camera 或 camera2 API 来支持新旧 API 版本而没有弃用说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的 camera2 API 让我很困惑.我想开发一个使用设备摄像头的应用(适用于 Android API 10 - 21).如 here 所述,我应该使用相机"API.

The new camera2 API confuses me. I want to develop an app (for Android APIs 10 - 21) which uses the device's camera. As stated here, I should use the "Camera" API.

但是,当我尝试将相机"API(android.hardware.Camera) 添加到清单的用户功能时,它被标记为已弃用.另一方面,我无法将其更改为camera2"API (android.hardware.camera2),因为它仅与 Android API 21+(Android 5 - Lollipop)兼容 - 会链接它也是,但我只能添加 2 个链接.

However, when I try to add the "Camera" API (android.hardware.Camera) to the manifest's user features, it is marked as deprecated. On the other hand, I cannot change it to the "camera2" API (android.hardware.camera2) since it is only compatible with Android API 21+ (Android 5 - Lollipop) - Would have linked it too, but I can only add 2 links.

我不仅希望我的应用在旧版 Android 上运行,而且还希望在最新版本上运行...

Not only do I want my app to run on older versions of Android, but also the newest one...

推荐答案

即使旧的相机 API 被标记为已弃用,它仍然可以正常工作,并且会在很长一段时间内保持这种状态(几乎所有使用相机的应用程序目前在 Play Store 上使用).

Even though the old camera API is marked as deprecated, it is still fully functional, and will remain so for quite a while (as nearly all camera-using applications on the Play Store use it currently).

您必须忽略 Android Studio 关于它已被弃用的抱怨,但如果您想支持早于 21 的 Android 版本,则必须使用旧 API.

You'll have to ignore Android Studio's complaints about it being deprecated, but if you want to support Android versions earlier than 21, you have to use the old API.

在 API 级别 21 上,您当然可以使用新的 API 及其新功能,但目前如果您在 API 之间切换,您必须在应用中维护一个完全独立的流程.不幸的是,这两个 API 具有足够不同的世界观,因此很难编写一个支持库来让您在旧设备上也使用类似新 API 的东西(如果没有,库从新 API 映射到旧 APIAPI 21+).

On API level 21, you can certainly use the new API and its new features, but currently you'll have to maintain a wholly separate flow in your app if you switch between the APIs. Unfortunately, the two APIs have a different enough of a worldview that it's hard to write a support library that would let you use something like the new API on older devices as well (where the library maps from the new API to the old API if not on API 21+).

这篇关于如何使用 Android 的 camera 或 camera2 API 来支持新旧 API 版本而没有弃用说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆