-
Notifications
You must be signed in to change notification settings - Fork 2
intent launcher SETUP
io.github.mobilebytelabs:cmp-intent-launcher:3.2.11
cmp-intent-launcher is zero-configuration for Gradle — 4 steps: add dependency, opt in,
wire the Android Activity, use the launcher in Compose.
[versions]
cmp-intent-launcher = "3.2.11"
[libraries]
cmp-intent-launcher = { module = "io.github.mobilebytelabs:cmp-intent-launcher", version.ref = "cmp-intent-launcher" }commonMain.dependencies {
implementation(libs.cmp.intent.launcher)
}@OptIn(ExperimentalIntentLauncherApi::class)
@Composable
fun MyScreen() {
val launcher = rememberIntentLauncher()
// ...
}// shared/build.gradle.kts
kotlin {
compilerOptions {
freeCompilerArgs.addAll(
"-opt-in=com.mobilebytelabs.kmptoolkit.intentlauncher.ExperimentalIntentLauncherApi"
)
}
}Call rememberIntentLauncher() at Compose composition time, then launch {} inside a coroutine:
@OptIn(ExperimentalIntentLauncherApi::class)
@Composable
fun OpenFilePicker() {
val scope = rememberCoroutineScope()
val launcher = rememberIntentLauncher()
Button(onClick = {
scope.launch {
val result = launcher.launch {
action = ResultContracts.GET_CONTENT
type = "application/pdf"
}
when (result) {
is IntentResult.Ok -> println("URI: ${result.data?.uri}")
is IntentResult.Cancelled -> { /* user dismissed */ }
is IntentResult.Failed -> logError(result.cause)
}
}
}) {
Text("Open PDF")
}
}val result = launcher.launch {
action = "com.example.ACTION_DO_SOMETHING"
extra("KEY_PARAM", "value")
targetPackage("com.example.targetapp")
}rememberIntentLauncher() registers an ActivityResultLauncher during Compose composition.
It must be called at the top level of a Composable — not inside a LaunchedEffect,
onClick, or conditional block.
On Android, make sure your host Activity extends ComponentActivity (or AppCompatActivity):
// androidApp/src/main/kotlin/MainActivity.kt
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
App() // rememberIntentLauncher() called inside here — OK
}
}
}No additional manifest permissions are required unless your specific intent action requires them (e.g.
READ_MEDIA_IMAGESfor image picking on API 33+).
| Platform | Behaviour |
|---|---|
| Android | Full ActivityResultLauncher — awaitable result with IntentData (URI, extras) |
| iOS / macOS |
onUnsupported → IntentResult.Failed(IntentError.UnsupportedPlatform); PHPicker/NSOpenPanel planned for v0.2 |
| JVM |
Desktop.open() / browse() — returns IntentResult.Ok(null) (no callback) |
| JS / wasmJs |
onUnsupported → IntentResult.Failed(IntentError.UnsupportedPlatform)
|
/sync-intent-launcher # Verify Gradle dependency (only gate needed)
/sync-intent-launcher --check # Dry run — show status, no writes
See CLAUDE_AI_SETUP.md for full docs.
** Partials**
App Intents
Bubble
Clipboard
Cookbook
- Clipboard Copy Text
- Clipboard Read Text
- Consumer Anon Key Setup
- Crashlytics Attribution Per Library
- Ifonline Block
- Index
- Index
- Index
- Index
- Open Url Compose
- Pick And Share Image
- React To Offline
- Register Firebase Hooks
- Share Pdf Android
- Share Text
- Wifi Vs Cellular
Firebase Analytics
In App Update
Intent Launcher
Inter App Comms
Modules
- Cmp App Intents
- Cmp App Intents Compose
- Cmp Bubble
- Cmp Clipboard
- Cmp Deep Link
- Cmp Firebase Analytics
- Cmp In App Update
- Cmp Intent Launcher
- Cmp Intent Launcher Compose
- Cmp Library
- Cmp Network Monitor
- Cmp Network Monitor Compose
- Cmp Observe
- Cmp Observe Koin
- Cmp Open Url
- Cmp Pdf Generator
- Cmp Product Tickets
- Cmp Remote Config
- Cmp Share
- Cmp Share Compose
- Cmp Toast
Network Monitor
Open Url
Pdf Generator
Remote Config
Share
Toast
User Tickets
General