First request
This smoke-test app creates a token provider and a January client, searches for a food, and shows the result on screen. Do the installation first, then add these files to a minimal Android app module.
1. Configure the app module
Put this in app/build.gradle.kts. If you did the installation in this module, add only the three providers.gradleProperty lines, the three buildConfigField lines, and buildFeatures.
plugins {
// AGP 9 compiles Kotlin itself. With AGP 8, also apply org.jetbrains.kotlin.android.
id("com.android.application")
}
val januaryTokenUrl = providers.gradleProperty("januaryTokenUrl").orNull ?: ""
val partnerSessionToken = providers.gradleProperty("partnerSessionToken").orNull ?: ""
val januaryEndUserId = providers.gradleProperty("januaryEndUserId").orNull ?: ""
android {
namespace = "com.example.januaryquickstart"
compileSdk = 36
defaultConfig {
applicationId = "com.example.januaryquickstart"
minSdk = 24
targetSdk = 36
versionCode = 1
versionName = "1.0"
buildConfigField("String", "JANUARY_TOKEN_URL", "\"$januaryTokenUrl\"")
buildConfigField("String", "PARTNER_SESSION_TOKEN", "\"$partnerSessionToken\"")
buildConfigField("String", "JANUARY_END_USER_ID", "\"$januaryEndUserId\"")
}
buildFeatures { buildConfig = true }
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
// Required by the SDK (it uses java.time), at any minSdk.
isCoreLibraryDesugaringEnabled = true
}
}
dependencies {
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
implementation("ai.january:january-sdk-android:0.3.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2")
}2. Add the manifests
Create app/src/main/AndroidManifest.xml:
The SDK's manifest adds the internet, camera, and microphone permissions. This app doesn't open the camera or the microphone.
Android blocks plain http:// requests, and the token relay on your computer serves http://. To test against it, allow cleartext traffic in debug builds only with app/src/debug/AndroidManifest.xml:
3. Add the activity and provider
Create app/src/main/java/com/example/januaryquickstart/MainActivity.kt. The provider is the one from Authentication, except that it leaves out Authorization when the session is blank, as it is for the local relay.
4. Build and run
Pick the token endpoint and pass its values as Gradle properties:
Token endpoint
-PjanuaryTokenUrl
-PpartnerSessionToken
Who picks the user
Your backend
https://your-backend.example/january-token
An app session token
Your backend, from the session. It ignores January-End-User-ID.
Token relay on this computer
http://10.0.2.2:8787/api/january/client-token
Leave it out
The relay, from January-End-User-ID
Hosted or LAN token relay
The relay's URL
The relay's RELAY_TOKEN
The relay, from January-End-User-ID
Always pass -PjanuaryEndUserId, the end-user ID the token is minted for. The app scopes requests with it; the SDK removes it from January requests because the token identifies the user. 10.0.2.2 is how the Android emulator reaches your computer. Start the relay first (Develop with the token relay).
The screen shows Connected, followed by up to five food names. An error shows its January error category, or an integration message. Remove session tokens from your shell history afterward; a real app reads its session from secure storage.
In a Compose app
Make the same call from a LaunchedEffect, with user created as above, once per signed-in account. Leaving the composition cancels the request.
Next: Example app
Last updated
Was this helpful?