Getting Started with CameraKit

This page helps you install and integrate CameraKit into your Android project. We recommend taking a look at the Developer Guides before you get started if this is your first time developing for Android. Here we will walk you through installation and basic usage to get you started on CameraKit.

Installation

Install CameraKit through the app-level build.gradle file for your Android project. In the dependencies section, add the following four dependencies:

dependencies {
implementation 'com.camerakit:camerakit:1.0.0-beta3.11'
implementation 'com.camerakit:jpegkit:0.1.0'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
}

CameraKit 1.0.0-beta3.10 relies on three additional dependencies, in addition to the CameraKit library, which are our own JPEGKit and two other Kotlin libraries.

Basic Usage

There are two components when creating a CameraKitView. First, the XML Layout file. Below is an example for CameraKitView with several properties set. To see all settable options, check out our <a href="/docs">Docs</a>.

<com.camerakit.CameraKitView
android:id="@+id/camera"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:keepScreenOn="true" <!-- keep screen awake while CameraKitView is active -->
app:camera_flash="auto"
app:camera_facing="back"
app:camera_focus="continuous"
app:camera_permissions="camera" />

Now, initialize the CameraKitView in the corresponding Java activity and override the following methods:

private CameraKitView cameraKitView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
cameraKitView = findViewById(R.id.camera);
}
@Override
protected void onStart() {
super.onStart();
cameraKitView.onStart();
}
@Override
protected void onResume() {
super.onResume();
cameraKitView.onResume();
}
@Override
protected void onPause() {
cameraKitView.onPause();
super.onPause();
}
@Override
protected void onStop() {
cameraKitView.onStop();
super.onStop();
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
cameraKitView.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

The first five methods handle lifecycle changes in the application, while the final method handles camera permissions. Run the application on your device to see the live camera preview.

That’s It!

Congratulations! You have successfully integrated CameraKit into your Android project. CameraKit is a powerful platform with many possibilities. Dive into our Docs for step-by-step tutorials on setup and image capture and learn more about the possible options and settings of CameraKit.