Skip to content

Android

This page describes the steps to integrate the Literal SDK into your Android application via a typical Gradle setup. Note, we provide two versions of the library for production and debug builds. The package name of the SDK is Literator, which is sometimes used interchangeably.

Requirements

The Literal SDK has the following requirements:

  • Minimum Android 5.0+ (API level 21+)
  • Compile option Java 8+
  • OkHttp 3+ (only if network insights are enabled)
  • compileSdkVersion 29+
  • An access token generated via Settings

Releases

The latest release of Literator is available via our maven repository. Ensure the maven repository is added.

debugImplementation("ai.literal:literator:1.9.2")

Maven Integration

In the project-level build.gradle or build.kts, add the necessary maven repositories:

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url "https://maven-dotmatrix.literal.ai/" }
    }
}
allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven { url = uri("https://jitpack.io") }
        maven { url = uri("https://maven-dotmatrix.literal.ai/") }
    }
}

App Integration

In the app-level build.gradle or build.kts file, add a reference to the library for debug and release build types:

dependencies {
    // ADD FULL SDK FOR DEBUG AND NOOP FOR RELEASE
    debugImplementation "ai.literal:literator:1.9.2"
    releaseImplementation "ai.literal:literator-noop:1.9.2"
}
dependencies {
    // ADD FULL SDK FOR DEBUG AND NOOP FOR RELEASE
    debugImplementation("ai.literal:literator:1.9.2")
    releaseImplementation("ai.literal:literator-noop:1.9.2")
}

Warning

Do not include the full SDK in production builds, as screen content is gathered (albeit after required permissions). For ease of integration, there is an additional no-op library that lets you avoid wrapping code in if (BuildConfig.DEBUG) blocks. The no-op variant merely obeys the provided interface, but does not run any code once built.

Initialize SDK

Ensure you have a custom Application class

In case you have not yet created an application class, follow these steps:

  1. Create a class MyApplication extending android.app.Application
  2. Flutter only: MyApplication should extend io.flutter.app.FlutterApplication
  3. Update AndroidManifest.xml by setting the full name under the "android:name" attribute under the tag. The full name should match the $package.$className
<application
    android:name="com.example.MyApplication">
    <!--...-->
</application>

Do not provide the full SDK in production builds as unintentional data will be gathered without the user's consent. The no-op variant merely obeys the provided interface, but does not run any code once built.

Dependency Injection Support (Dagger, Hilt, Koin etc..)

To integrate Literator with Dagger, simply return the result of Literator.start(.....) in a @Provides annotated method.

If you need assistance integrating the SDK with dependency injection frameworks, feel free to reach out via support.

Initialize LiteratorClient within Application onCreate(). Replace <access_token> with an access token generated via Settings.

The start method must be called once, any subsequent call will have no effect. Optional configurations can be added via LiteratorConfig.builder() - see the API section for more details.

import ai.literal.core.client.Literator
import ai.literal.core.client.base.LiteratorConfig  

class MyApplication : Application() {
    override fun onCreate() {
        super.onCreate()

        val literator = Literator.start(this, "<access_token>", LiteratorConfig.defaultConfig())
    }
}
import ai.literal.core.client.Literator;
import ai.literal.core.client.base.LiteratorConfig;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        LiteratorClient client = Literator.start(application, "<access_token>", LiteratorConfig.defaultConfig());
    }
}
import ai.literal.core.client.Literator;
import ai.literal.core.client.base.LiteratorConfig;
import io.flutter.app.FlutterApplication;

public class MyApplication extends FlutterApplication {
    @Override
    public void onCreate() {
        super.onCreate();

        Literator.start(this, "<access_token>", LiteratorConfig.defaultConfig());
    }
}  
import ai.literal.core.client.Literator
import ai.literal.core.client.base.LiteratorConfig
import io.flutter.app.FlutterApplication

class MyApplication : FlutterApplication() {
    @Override
    fun onCreate() {
        super.onCreate()

        Literator.start(this, "<access_token>", LiteratorConfig.defaultConfig())
    }
}

Confirm the Literal SDK is running on start-up by filtering on the Literator tag in Logcat:

 Literator  D  Literator initialized.
 Literator  D  Attempting to establish new session.
 Literator  D  Session successfully started. You should see a new notification to start a recording.

You should see a persistent notification to initiate a recording session if a valid internet connection is present and the access token is valid as per the usage guide.

Next up!