Simplest ever camera app in Android

In recent times we have seen a number of libraries launched by Google under androidx
one of them in camerax
which is under heavy development as of now. But some weeks back it had officially jumped into the beta stage. So today we will see how we can use this library to create a very simple camera app.
So let's get started.
First of all, we need to declare camerax dependencies in our build.gradle
.
These libraries provide us with a cameraview
class which we will use in this example.
Also, we need to enable Java 8 in build.gradle
file.
Now, we will create our UI with cameraview
and two buttons
, one for recording videos and one for capturing images.
As you can see we can define all available camera properties directly in our layout file like lens facing, scale type, pinch to zoom, flash etc.
We can also add these properties programmatically from our Kotlin/Java file.
Now after all these we will create some methods for requesting camera and audio permissions so our app can use these hardware components.
Now we will define paths to our storage for creating ‘image’ & ‘video’ files.
Now, we will create two methods, one for recording video and one for capturing images.
That’s it, we just created a camera app with video recording and image capture functionality.

Check out the source code: https://github.com/iambaljeet/CameraXView
After all these steps your app is ready to de deployed to your device. Simply run your app and you can see a camera view with recording
and capture
functionality.