Android CameraX — An Emergence

Hannah Olukoye
May 5 · 2 min read
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 :-)

Quick Code

Find the best tutorials and courses for the web, mobile, chatbot, AR/VR development, database management, data science, web design and cryptocurrency. Practice in JavaScript, Java, Python, R, Android, Swift, Objective-C, React, Node Js, Ember, C++, SQL & more.

Hannah Olukoye

Written by

Mobile Developer — Android :: Sometimes a drummer

Quick Code

Find the best tutorials and courses for the web, mobile, chatbot, AR/VR development, database management, data science, web design and cryptocurrency. Practice in JavaScript, Java, Python, R, Android, Swift, Objective-C, React, Node Js, Ember, C++, SQL & more.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store