An Introduction to CameraX

Gabriel Tanner
AndroidPub
Published in
6 min readJun 3, 2019

--

Photo by Evan Wise on Unsplash

CameraX is a new Jetpack library introduced at Google IO 2019 which was built to help make camera development easier. It provides an easy to use API environment which works across most Android devices with backwards compatibility to Android 5.0 (API Level 21).

Today, we are going to talk about how CameraX solves some of the problems developers were facing with the old camera API and take a look at how we can create our own camera app using CameraX.

How it helps

Now the question remains how CameraX is different from the other camera APIs and how it can help us develop better camera apps. Here are some of the greatest improvements and benefits CameraX provides us with.

Ease of use:

CameraX provides several predefined use cases like a preview, image capture and image analysis which work on almost every device on the market. This allows us developers to focus on the tasks we need to get done instead of spending our time writing basic functionality and managing requirements for different devices.

Consistency across devices:

Managing the consistency across different devices is hard and there is a lot to account for including the aspect ratio, rotation and orientation. CameraX takes care of that basic configuration and greatly reduces our test burden as developers.

Add ons:

CameraX also enables us developers to use the same camera features that the pre-installed camera app provides, with little code requirements. This is possible by providing optional add ons that add effects like Portrait, HDR, Night, and Beauty within our applications.

Project:

By now we should know why CameraX is useful and where it can improve our development experience. Now let’s take a look at how we can develop a simple camera application which allows us to take photos, enable the flash and switch lenses.

So, without wasting any further time, let’s get started.

Importing the dependencies

Before we can start creating our UI we first need to import the needed dependencies for our project. We can do so by adding the following…

--

--

Gabriel Tanner
AndroidPub

Android Developer | Web Developer | Part-time Blogger | Catch me at https://gabrieltanner.org/ | Buy me a coffee buymeacoff.ee/gabrieltanner