Quick Code
Published in

Quick Code

Android CameraX — An Emergence

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




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.

Recommended from Medium

Android Architecture Patterns

تحميل Gangstar New Orleans OpenWorld

Hack: Integrating Gitlab with Fastlane for Android

How to debug an Android application over WiFi

App Battery Efficiency Workaround

Android App Bundle Complete Guide

Working with Kotlin Sealed Classes

Android Beautiful Progress Dialog

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
Hannah Olukoye

Hannah Olukoye

Mobile Developer — Android :: Sometimes a drummer

More from Medium

Resolving HAXM Issue in Android Studio for Windows

JPEG compression in Android

Graph of JPEG compressions ratios between original file and compressed file depending on the specified quality.

How to force turned on the GPU acceleration of Android Webview

MVP Implementation in Android with Kotlin