Add image injection SDK to your Android app

Learn how to implement Kobiton’s custom SDK in your Android application to enable Image Injection.

Prerequisites

  • Android 9 or newer.

  • An Android project with Gradle build tool.

  • The application uses camera2 library. See the full list of supported methods in camera2.

  • Download the Image Injection SDK file here. The downloaded file name should be: camera2.arr.

Integrate the SDK

Create a new folder named libs under <project_folder>/app, where <project_folder> is the root folder of the Android project to be altered. Copy the downloaded camera2.arr file into the newly created folder.

The camera2 file under the libs folder

Under <project_folder>/app, edit the build.gradle file and add the following line under dependencies to allow your application to use the .arr file:

implementation fileTree(dir: 'libs', include: ['*.aar'])

Under <project_folder>/app/src/main, edit the AndroidManifest.xml file and add the following lines within the application tag. This service is used to connect the SDK to Kobiton Server.

<service android:name="kobiton.hardware.camera2.ImageInjectionClient" />

The new service line in android manifest

Within the same AndroidManifest.xml file as above, add the following lines within the manifest tag to grant the 2 permissions INTERNET and ACCESS_NETWORK_STATE for the SDK to connect to Kobiton’s Server.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

The new uses permission line in android manifest

Replace all texts in the project according to the below table to replace the stock Android library with the custom Kobiton library:

Replace With

android.hardware.camera2.CameraCaptureSession

kobiton.hardware.camera2.CameraCaptureSession

android.hardware.camera2.CameraDevice

kobiton.hardware.camera2.CameraDevice

android.hardware.camera2.CameraManager

kobiton.hardware.camera2.CameraManager

android.hardware.camera2.CaptureRequest

kobiton.hardware.camera2.CaptureRequest

android.hardware.camera2.params.SessionConfiguration

kobiton.hardware.camera2.params.SessionConfiguration

android.media.ImageReader

kobiton.media.ImageReader

Update the CameraManager’s initial method by replacing Context.getSystemService(Context.CAMERA_SERVICE) with CameraManager.getInstance(context). For example, replace:

private val cameraManager: CameraManager by lazy {
        val context = requireContext().applicationContext
        context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
}

with

private val cameraManager: CameraManager by lazy {
    CameraManager.getInstance(requireContext().applicationContext)
}

After all the above changes are made, package your app into an .apk, .aab or .zip file.

Upload the app package to the app repository or to the cloud and install the app on a Kobiton device, then follow the guides to use image injection in a manual session or an automation session.