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

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

问题描述

新的 camera2 API 让我很困惑.我想开发一个使用设备相机的应用(适用于 Android API 10 - 21).如此处所述,我应该使用相机"应用程序接口.

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 商店使用它).

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 映射到旧 API)API 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's camera 或camera2 API 支持新旧API 版本而无需弃用说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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