The Kotlin Android Camera2 API introduction describes how to implement the Android Camera2 API using the Kotlin programming language.
Each episode will be released on a weekly basis. Though there is the option of getting access to all the episodes straight away by buying the series.
The first Kotlin on Android episode introduces the initial code base that is provided from git.
And then moves on to adding a TextureView to the Android fragment. A TextView SurfaceTextureListener does need to be implemented. Which will notify when the surface texture is available.
Before the Android Camera2 API can be accessed, permission must be granted by the user.
From Android 6.0 (Marshmellow) and onwards, Android runtime permissions must be implemented.
To simplify this process, the EasyPermissions libary is used.
This Kotlin on Android tutorial describes how to install and use the EasyPermission library.
Resulting in the user being requested to grant permission for the camera.
One of the first steps of using the Android camera2 API is to decide which camera device to connect to.
This will normally either be the forward or rear facing lens. The Android camera2 API provides ids for both of these lenses.
In this Kotlin on Android tutorial we will describe how to get the camera device id for a particular facing lens. And how the CameraManager & CameraCharateristics are used to achieve this.
Once the camera device id has been found, a connection to the camera device can be requested.
If successful, a camera device will be created and opened.
In this Kotlin on Android tutorial we will describe how to use the camera manager and camera device state callbacks to open a connection to the camera device.
Upon successfully opening a connection to a camera device, camera capture requests can then be made.
First, a camera capture session must be created. A list of surfaces must be provided as targets for capturing the camera data to. And in this Kotlin on Android tutorial, we will be using the TextureView surface to capture images from the rear camera.
To start the preview capture, a request must be made on the camera capture session.
In this Kotlin on Android tutorial we will describe the steps for switching between the forward and rear facing camera lenses.
An item in the navigation drawer will be added. This will be used for switching between the camera lenses.
For closing one camera and starting another there is a defined process flow. And in this Kotlin on Android tutorial we will clearly describes the steps involved.
From Android 7.0 and later it is recommended to use the SurfaceView instead of the TextureView.
And in this Kotlin on Android tutorial, we will describe how to add a SurfaceView target to the camera device.
Note there is an issue when using the navigation drawer with a SurfaceView. Where the SurfaceView get drawn over the navigation drawer.
This Kotlin on Android tutorial will also address this issue and describe the steps to bring the navigation drawer back on top of the screen.