Android context
// Get the Application instance
val app: Application = applicationContext()
// Execute a block with the Application as receiver
withApplicationContext { app ->
app.getSystemService(...)
}
Activity detection
val activity: Activity? = context.findActivity()
URI utilities
// Check if a URI uses the file scheme
val isFile: Boolean = uri.isFileUri
// Convert file:// URI to content:// via FileProvider
val shareable: Uri = uri.shareableUri
// Share a URI via the Android share sheet
uri.share()
Opening URLs and sharing text
openUrl("https://example.com")
shareText("Check this out!")
Encoding/decoding
val encoded = "hello world".encodeEscaped() // "hello%20world"
val decoded = encoded.decodeEscaped() // "hello world"
Date & time formatting
import java.time.*
val now = LocalDateTime.now()
now.formatDateTime() // "July 11th, 2026 at 3:45"
now.toLocalDate().formatDate() // "July 11th, 2026"
dayWithSuffix(1) // "1st"
dayWithSuffix(2) // "2nd"
dayWithSuffix(3) // "3rd"
dayWithSuffix(11) // "11th"
val duration: Duration = ...
val dateTime: LocalDateTime = duration.asLocalDateTime()
Human-readable sizes
val bytes: Long = 1_500_000L
bytes.humanBytes() // "1.5 MB"
val intBytes: Int = 1024
intBytes.humanBytes() // "1.0 KB"
Error handling
// Extract user-friendly error message
val message: String = throwable.extractMessage()
// Try a block, returning null on non-cancellation exceptions
val result: Any? = tryOrNull { riskyOperation() }
Text file detection
val isText: Boolean = isTextFile(uri, contentResolver)
Architecture detection
val arch: Architecture = currentArchitecture()
arch.toString() // "aarch64", "arm", "x86", "x86_64"
Architecture.Aarch64
Architecture.Arm
Architecture.X86
Architecture.X86_64
Architecture.Unknown
Compose modifiers
import com.klyx.api.util.thenIf
import com.klyx.api.util.conditional
import com.klyx.api.util.applyIfNotNull
import com.klyx.api.util.applyIf
// Apply modifier only if condition is true
Modifier.thenIf(condition) { Modifier.padding(16.dp) }
// Alternative syntax
Modifier.conditional(condition) { padding(16.dp) }
// Apply only if value is non-null
Modifier.applyIfNotNull(value) { padding(it.dp) }
// Ternary-like syntax
Modifier.applyIf(condition, { padding(16.dp) }, { padding(8.dp) })
// Debug border
Modifier.debugBorder(enabled = true) // Shows red border
StateFlow helpers
val stateFlow = someFlow.stateInWhileSubscribed(viewModelScope)
val eagerlyState = someFlow.stateInEagerly(viewModelScope)
val lazilyState = someFlow.stateInLazily(viewModelScope)
Toast
// From within a KlyxPlugin
showToast("Operation complete")
showFailureToast("Something went wrong")
showFailureToast(exception)
// From any composable
val toastHostState = LocalToastHostState.current
toastHostState.showToast("Hello")
toastHostState.showFailureToast(exception)
Toast duration
ToastDuration.Short // 3.5 seconds
ToastDuration.Long // 6.5 seconds
ToastDuration.Custom(5000) // Custom duration in ms