How to use Android's camera or camera2 API to support old and new API versions without deprecation notes? Ask Question

How to use Android's camera or camera2 API to support old and new API versions without deprecation notes? Ask Question

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.

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.

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

ベストアンサー1

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).

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 を切り替える場合は、アプリ内で完全に別のフローを維持する必要があります。残念ながら、2 つの API の世界観は大きく異なるため、古いデバイスでも新しい API のようなものを使用できるようにするサポート ライブラリを作成するのは困難です (API 21+ でない場合は、ライブラリが新しい API から古い API にマップされます)。

おすすめ記事