Skip to main content

Get Started

Prerequisites

Before using the Klleon Ondevice SDK, the following preparations are required:

  1. Kleon Studio Account: A Kleon Studio account is required to use SDK features. If you don't have an account, please sign up first.
  2. SDK Key Issuance: After domain registration, a unique sdk_key for use with that domain will be issued. This key is required for SDK initialization.
  3. Avatar ID: You need the avatarId of the AI avatar you want to use.

Permissions

AndroidManifest.xml

Add the required permissions to your AndroidManifest.xml:

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

Handling Permissions in Code

class MainActivity : ComponentActivity() {
private val requiredPermissions = arrayOf(
Manifest.permission.RECORD_AUDIO
)

private val permissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestMultiplePermissions()
) { permissions ->
handlePermissionResults(permissions)
}

private fun checkPermissions(): Boolean {
return requiredPermissions.all { permission ->
ContextCompat.checkSelfPermission(this, permission) == PackageManager.PERMISSION_GRANTED
}
}

private fun requestPermissions() {
val permissionsToRequest = requiredPermissions.filter { permission ->
ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED
}.toTypedArray()

if (permissionsToRequest.isNotEmpty()) {
permissionLauncher.launch(permissionsToRequest)
}
}

private fun handlePermissionResults(permissions: Map<String, Boolean>) {
val deniedPermissions = permissions.filter { !it.value }.keys

if (deniedPermissions.isEmpty()) {
Log.d("MainActivity", "All permissions granted")
initializeApp()
} else {
Log.w("MainActivity", "Permissions denied: $deniedPermissions")
// Handle denied permissions
}
}
}

SDK Initialization

Basic Setup

import io.klleon.ondevice.KlleonOndeviceSdk
import io.klleon.ondevice.ResourceManager
import io.klleon.ondevice.render.KlleonSdkView

// Share a single instance across the entire app
object SdkConfig {
val sdk = KlleonOndeviceSdk()
}

class MainActivity : ComponentActivity() {
private val klleonOndeviceSdk = SdkConfig.sdk
private val resourceManager = ResourceManager()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

if (checkPermissions()) {
initializeApp()
} else {
requestPermissions()
}
}

private fun initializeApp() {
setContent {
OndeviceSampleTheme {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
WorkerScreen(klleonOndeviceSdk = klleonOndeviceSdk)
}
}
}

// Initialize resources (cache copy + YUV conversion + memory loading)
resourceManager.init(
context = this,
mp4FileName = "loop_sample.mp4",
npzFileName = "loop_sample.npz",
styleFileName = "loop_sample.style",
avatarId = "character_001",
onSuccess = {
// Resources ready — play() can be called
},
onError = { error ->
Log.e("MainActivity", "Resource preparation failed", error)
}
)
}
}

Starting the SDK (play)

// play() is a suspend function, so call it within a coroutine
CoroutineScope(Dispatchers.IO).launch {
klleonOndeviceSdk.play(
context = this@Activity, // Context
klleonSdkViewInstance = sdkView, // KlleonSdkView instance
sdkKey = "YOUR_SDK_KEY", // SDK key
avatarId = "character_001", // Avatar ID
language = "ko_kr" // Language (ko_kr, en_us, ja_jp)
)
}

Parameters:

ParameterTypeRequiredDescription
contextContextOCurrent context
klleonSdkViewInstanceKlleonSdkView?ORendering view instance
sdkKeyStringOSDK authentication key
avatarIdStringOAI avatar ID
languageStringOLanguage code (ko_kr, en_us, ja_jp)

Next Steps

After completing the setup:

  1. Check the API Reference for available methods
  2. Follow the Guides for optimal integration
  3. Check the Usage Examples for implementation patterns