-
Notifications
You must be signed in to change notification settings - Fork 2
open url README
Cross-platform URL opening for Kotlin Multiplatform — browser, email, maps, phone, SMS, and custom URI schemes across all 14 KMP targets.
// build.gradle.kts
implementation("io.github.mobilebytelabs:kmp-open-url:<version>")No additional setup required on Android — the library auto-initialises via a ContentProvider that is merged into your manifest automatically.
import com.mobilebytelabs.kmptoolkit.openurl.*
// Open any URL with the default system handler
openUrl("https://github.com/MobileByteLabs") // → browser
// Force browser (bypass app-association rules)
openInBrowser("https://accounts.google.com/...") // → always browser
// Open with a specific app category
openWithApp("mailto:hello@example.com", AppHint.EMAIL) // → Gmail / Apple Mail
openWithApp("geo:37.7749,-122.4194", AppHint.MAPS) // → Google Maps / Apple Maps
openWithApp("tel:+1-800-555-0100", AppHint.PHONE) // → phone dialer
openWithApp("sms:+1-800-555-0100", AppHint.SMS) // → messaging app
// Android-only: explicit package name
openWithApp("https://maps.google.com", AppHint.Custom("com.google.android.apps.maps"))
// Check before opening
if (canOpen("myapp://deep-link/home")) {
openUrl("myapp://deep-link/home")
}Opens the URL using the platform's default handler. Returns true if accepted, false otherwise. Never throws.
Forces the URL to open in the system web browser, bypassing app-association rules. Never throws.
Opens the URL with a preferred app category hint. Returns an OpenUrlResult for richer error handling. Never throws.
Returns true if the platform can handle the URL without actually opening it. Never throws.
| Value | Effect |
|---|---|
AppHint.DEFAULT |
Let the OS choose the best handler |
AppHint.BROWSER |
Force system browser |
AppHint.EMAIL |
Prefer email client (mailto:) |
AppHint.MAPS |
Prefer maps app (geo://, maps:) |
AppHint.PHONE |
Prefer phone dialer (tel:) |
AppHint.SMS |
Prefer SMS app (sms:) |
AppHint.Custom(pkg) |
Android only — explicit package name |
sealed class OpenUrlResult {
object Success // URL was opened
object NoHandler // No app can handle it
data class Error(val message: String) // Unexpected error
}
// Exhaustive matching
when (result) {
OpenUrlResult.Success -> showConfirmation()
OpenUrlResult.NoHandler -> showFallbackUI()
is OpenUrlResult.Error -> log(result.message)
}| Platform | openUrl |
openInBrowser |
openWithApp |
canOpen |
|---|---|---|---|---|
| Android | ✅ | ✅ | ✅ (all hints) | ✅ |
| iOS | ✅ | ✅ | ✅ | ✅ |
| macOS | ✅ | ✅ | ✅ | ✅ |
| tvOS | ❌ NoHandler | ❌ NoHandler | ❌ NoHandler | ❌ false |
| watchOS | ❌ NoHandler | ❌ NoHandler | ❌ NoHandler | ❌ false |
| JVM Desktop | ✅ | ✅ | ✅ | ✅ |
| JS Browser | ✅ | ✅ | ✅ | ✅ |
| JS Node | ✅ (via open) |
✅ | ✅ | |
| Linux Native | ✅ (xdg-open) | ✅ | ✅ | ✅ |
| Windows Native | ✅ (ShellExecuteW) | ✅ | ✅ | ✅ |
| wasmJs | ✅ | ✅ | ✅ | ✅ |
| wasmWasi | ❌ false | ❌ false | ❌ NoHandler | ❌ false |
-
Never throws — all functions catch exceptions internally and return
false/NoHandler. - No URL encoding — the library passes URLs as-is; encoding is the caller's responsibility.
- Outgoing only — this library does not handle incoming deep links into your app.
-
AppHint.Customfallback — if the specified Android package is not installed, the library retries withAppHint.DEFAULTbefore returningNoHandler.
** 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