I've been working on a customized camera app, it only changes the layout of how the camera is shown but it doesn't change any core feature of the camera.
As I searched, I found these libraries: hardware.camera2 , hardware.camera and cameraX.
And my app should work properly on minSdk 17. so my question is: is camera api deprecated so I can use camera2 on my app?
As I saw in documents you could only use camera2 with cameraManager on API 21 and higher.
Can anyone help me with what library I should use and how I could implement it?
hardware.camera (also known as Camera1) was deprecated in API level 21.
hardware.camera2 (also known as Camera2) was introduced in API level 21.
camerax is part of the Jetpack suite of libraries, and is built on top on Camera2, so is backward compatible to API level 21.
If your app has a minSdk version of 17, you can define a single Camera interface to use in your app, then provide 2 implementations for it using camera1 on API levels below 21, and CameraX/Camera2 on API levels starting at 21. Whether you choose Camera2 or CameraX depends mostly on your camera features. CameraX provides fairly easy to use APIs for preview, image analysis and image capture, and resolves device compatibility issues. You can take a look at its official documentation to see whether it meets your app's requirements, if it does, you can get started on it with this codelab. Camera2 provides a more fine grained control over the camera, but come with more complexity to handle it, you can take a look at what it provides through its official documentation.
Related
What is Android CameraX?
There is a session about CameraX planned in Google I/O 2019. What is it? Is it a new framework API? Is it a new library?
https://events.google.com/io/schedule/events/8d400240-f31f-4ac2-bfab-f8347ef3ab3e
Does it mean that Camera2 API is deprecated?
https://github.com/googlesamples/android-Camera2Basic
What is Android CameraX?
CameraX is a new Jetpack library that lets developers control a device's camera and focuses on compatibility across devices going back to API level 21 (Lollipop). It was announced at Google I/O 2019 and has a dedicated documentation page alongside an official sample.
Does it mean that Camera2 API is deprecated?
Camera2 API is not deprecated; in fact, it is the foundation that CameraX is built on. CameraX also provides a Camera2 interop API that lets developers extend their CameraX implementation with Camera2 code.
For more information, the official documentation is available at https://developer.android.com/camerax
In Google IO 2019, Google added another powerful tool for camera development in Android development called CameraX as part of Jetpack
Few Features of CameraX
It is backwards compatible till Android 5.0 / Lollipop (API 21) and
it works with at least 90% devices in the market.
Under the hood, it uses and leverages the Camera 2 APIs. It
basically, provide the same consistency as Camera 1 API via Camera 2
Legacy layer and it fixed a lot of issues across the device.
It also has a lot of awesome advanced features like Portrait, HDR,
Night mode etc (Provided your Device supports that).
CameraX has also introduced use cases which allow you to focus on the
the task you need to get it done and not waste your time with specific devices. Few of them are Preview, Image Analysis, Image Capture.
CameraX doesn't have specific call/stop methods in onResume() and
onPause() but it binds to the lifecycle of the View with the help of
CameraX.bindToLifecycle()
The following is the few lists of known issues fixed with CameraX,
what more you can do with CameraX
You can also create Video Recorder App using CameraX
Add multiple extensions like Portrait Mode, HDR etc.
We can also use Image Analysis to perform Computer Vision, ML. So it
implements Analyzer method to run on each and every frame.
To read more about CameraX refer here
for Getting Started with CameraX
You can check the official doc:
CameraX is an addition to Android Jetpack that makes it easier to add camera capabilities to your app. The library provides a number of compatibility fixes and workarounds to help make the developer experience consistent across many devices.
You can use cameraX to interface with a device’s camera through an abstraction called a use case. The following use cases are currently available:
Preview: prepares a preview SurfaceTexture
Image analysis: provides CPU-accessible buffers for analysis, such as for machine learning
Image capture: captures and saves a photo
Use cases can be combined and active concurrently.
Just add the dependencies:
dependencies {
// CameraX core library
def camerax_version = "1.0.0-alpha01"
implementation "androidx.camera:camera-core:$camerax_version"
// If you want to use Camera2 extensions
implementation "androidx.camera:camera-camera2:$camerax_version"
}
For information on how to use the CameraX library check here.
I'm building an App which is similar to social media where people can share photos and videos like Instagram. That's why Camera is very important for my app. Now camera2 API is confusing me. I want to run my app on API level 11+ . I know camera2 is only available in API level 21+ So, I need to design two APIs one(camera) for older version and second(camera2) for higher version. Problem is that I just started to learn Android and I do not know what is the main difference between these two APIs.
What main features are available in Camera2 API ?
Or Is there any drawback of Old Camera API ?
I need three things in my App.
1- Simple capture photos
2- Burst pictures (To create GIF Image)
3- Simple video recording.
Which Camera API is good for me ?
The old camera API will work fine for #1 and #3; if you're OK with video-resolution GIFs, you can do #2 as well.
You'll need camera2 (and then devices that support fast, full-resolution capture - see the BURST_CAPTURE capability, or any device that supports the FULL hardware level.), if you want bursts at resolutions above ~1080p.
You can probably start with the CameraView unofficial support library, and modify it as needed. It has support for both APIs, selected based on API level of the device.
I need to create a custom camera in Android that supports both higher and lower version.I am new to android.I have research a lot I have the code ready for hardware camera i.e. for the api less than 21.But I am finding hard time searching the code that supports camera hardware 2.
The old deprecated camera API still works on Android 21 and above. But you are right, using the new API is preferable, and gives you more options and better performance.
You can start with the official Camera2Basic sample.
Are all API level 21 devices required to expose the camera2 package for all cameras(e.g. front,back) at least in the LEGACY support type?
In other words, is it possible(and does it happen) for a android 5 camera to be more functional under the deprecated android.hardware.Camera interface, than under the new android.hardware.camera2 interface, or even for the camera device to be impossible to find or use as a android.hardware.camera2 device?
It's mandatory that camera devices are exposed through android.hardware.camera2 (API2) as well as the deprecated android.hardware.Camera (API1).
However, at the LEGACY level, some features available in API1 may not be available in API2. Primarily, this affects the available recording resolutions, as LEGACY API2 is limited to the maximum preview size available in API1.
In addition, any OEM extensions to API1 won't be available through API2.
I am working on custom camera and using deprecated Camera api's instead of Camera2 api's in Android L but I am facing lots issues in preview. One of them is, It is showing dark preview and another problem is setSceneMode and setColorEffects making no effect. Please let me know the workaround if any one out there used deprecated camera api's in v21.
Setting a high FPS which may produce a dark preview in some devices, because a high FPS lowers the exposure compensation. Setting it to a variable range instead of a fixed one can solve the problem for the devices that present such issue.
A device may return a set of supported ranges such as for example: [10-15, 15-30, 30-30]. In this example you would pick up any of the variable ones, and avoid the fixed one [30-30]. Note that fixed ranges are meant to be for video only.
Turns out Camera.Parameters is deprecated.
This class was deprecated in API level 21.
We recommend using the new android.hardware.camera2 API for new applications.
Android Developer - Camera.Parameters
You should use this instead for devices with API level > 21:
Android Developer - android.hardware.camera2