Android CameraX — An Emergence

Hannah Olukoye
Quick Code
Published in
2 min readMay 5, 2021

--

Photo by Douglas Gausi on Unsplash

Several APIs were introduced and upgraded in the recent release of Android 11. The goal was to create simple and intuitive APIs that will allow Android developers to tap into innovative ideas supported by the Android platform.

These APIs included:

  1. Media Control APIs
  2. System UI
  3. Device Controls
  4. Biometric Authentication Updates
  5. CameraX
  6. AppCompat
  7. WebKit

In this article, I will focus on CameraX — An API that will allow Android engineers to build camera apps quickly and reliably. CameraX is in the beta phase, running on 90% of Android Test lab devices. It was built on the same foundation as previous camera APIs like Camera2 and Camera APIs. So now developer can extend CameraX implementation with their Camera2 code.

One cool thing about CameraX is that it introduces use cases — Use cases allow you as a developer to focus on the task you need to get done instead of managing other device-specific refinements. Other cool functionality includes:

  • A preview — As an Android developer you get to view an image on the display before capture.
  • Image analysis — This targets developers integrating to Machine Learning Kits. As an Android developer, you get to access a buffer seamlessly for use to pass, into your Machine Learning model algorithms.
  • Image capture — To save high-quality images.

Next, we will look at some simple steps using a sample code that will help you set up and implement a preview using CameraX API as an Android Developer.

  1. Add the PreviewView element in your layout activity_main.xml file.

In your MainActivity.kt file.

  1. Create an instance of the CameraProvider and then verify that its initialization succeeded after the view is created.
  2. Bind the preview to the camera provider we set up by creating a Preview with the builder class. First, we specify the desired camera LensFacing option, then, we bind the selected camera on the surfaceProvider and any other use cases to the activity’s lifecycle and finally we connect the Preview to the PreviewView.

Have fun using CameraX.

Thank you Egbai Smile Mmumene for your input in this :-)

--

--