Get Started
Prerequisites
Before using the Klleon Ondevice SDK, the following preparations are required:
- Kleon Studio Account: A Kleon Studio account is required to use SDK features. If you don't have an account, please sign up first.
- SDK Key Issuance: After domain registration, a unique
sdk_keyfor use with that domain will be issued. This key is required for SDK initialization. - Avatar ID: You need the
avatarIdof 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
context | Context | O | Current context |
klleonSdkViewInstance | KlleonSdkView? | O | Rendering view instance |
sdkKey | String | O | SDK authentication key |
avatarId | String | O | AI avatar ID |
language | String | O | Language code (ko_kr, en_us, ja_jp) |
Next Steps
After completing the setup:
- Check the API Reference for available methods
- Follow the Guides for optimal integration
- Check the Usage Examples for implementation patterns