Android SDK Reference (Kotlin)
This page is a comprehensive API reference for the OpenLynk Android SDK (Kotlin). For a step-by-step integration walkthrough, see the Android Integration Tutorial.
Installation
The SDK is distributed as a single file:
OpenlynkSDK.kt
Add this file to your Android project. The SDK depends on:
kotlinx.coroutines(standard in modern Android projects)- Standard Android SDK APIs
Factory Method
Create an SDK instance using the companion object factory method:
val sdk = OpenlynkSDK.create(
context = applicationContext,
appId = "your-app-id",
apiKey = "ol_your_api_key",
baseURL = "https://openlynk.io", // optional
config = OpenlynkSDKConfig() // optional
)
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
context | Context | Yes | — | Android application context |
appId | String | Yes | — | Your app ID from the OpenLynk dashboard |
apiKey | String | Yes | — | Your API key (format: ol_...) |
baseURL | String | No | "https://openlynk.io" | API base URL |
config | OpenlynkSDKConfig | No | OpenlynkSDKConfig() | SDK configuration options |
Methods
All methods are callback-based using Result types.
| Method | Callback Type | Description |
|---|---|---|
init(completion) | (Result<Unit>) -> Unit | Initialize the SDK, send heartbeat, restore pending links |
handleIncomingUri(uri, completion) | (Result<ParsedDeepLink>) -> Unit | Parse an incoming App Link URI |
parseDeepLink(uri, callback) | (Result<ParsedDeepLink>) -> Unit | Parse a deep link URI manually |
createLink(destination, metadata, callback) | (Result<CreatedLink>) -> Unit | Create a shareable deep link |
restorePendingLinks(userEmail, callback) | (Result<List<RestoredLink>>) -> Unit | Restore deferred links by email |
restorePendingLinksForAnonymous(callback) | (Result<List<RestoredLink>>) -> Unit | Restore deferred links using device fingerprint |
getLinkBySlug(slug, hostname, callback) | (Result<LinkDetails>) -> Unit | Fetch link details by slug |
OpenlynkSDKConfig
data class OpenlynkSDKConfig(
val autoRestoreOnInit: Boolean = true,
val userEmailProvider: (suspend () -> String?)? = null,
val onRestoredLinks: ((List<RestoredLink>) -> Unit)? = null,
val onDeepLink: ((ParsedDeepLink) -> Unit)? = null,
)
| Property | Type | Default | Description |
|---|---|---|---|
autoRestoreOnInit | Boolean | true | Automatically restore pending links when init() is called |
userEmailProvider | suspend () -> String? | null | Suspending function that returns the current user's email |
onRestoredLinks | (List<RestoredLink>) -> Unit | null | Callback invoked when deferred links are restored |
onDeepLink | (ParsedDeepLink) -> Unit | null | Callback invoked when a deep link is parsed |
Callback Interfaces
The SDK provides typed callback interfaces for each operation:
interface RestoreCallback {
fun onSuccess(links: List<RestoredLink>)
fun onError(error: Exception)
}
interface CreateLinkCallback {
fun onSuccess(link: CreatedLink)
fun onError(error: Exception)
}
interface GetLinkCallback {
fun onSuccess(details: LinkDetails)
fun onError(error: Exception)
}
Handling Incoming URIs
:::caution Key Difference from Flutter
The Android SDK does not start an automatic link listener. You must call handleIncomingUri() from your Activity when an App Link opens your app.
:::
Activity example:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
intent?.data?.let { uri ->
sdk.handleIncomingUri(uri) { result ->
result.onSuccess { deepLink ->
// Navigate to deepLink.destinationPath
}.onFailure { error ->
Log.e("OpenLynk", "Failed to handle URI", error)
}
}
}
}
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
intent?.data?.let { uri ->
sdk.handleIncomingUri(uri) { result ->
result.onSuccess { deepLink ->
// Navigate to deepLink.destinationPath
}
}
}
}
Related Pages
- Data Types Reference — full field-level documentation for
CreatedLink,ParsedDeepLink,RestoredLink, andLinkDetails - Android Integration Tutorial — step-by-step guide to integrating the SDK
- Android App Links Guide — configure App Links for your app
What's Next?
- Configure App Links so deep links open your app
- Learn how to handle deep links in your Android app
- Implement deferred deep linking for users who install after clicking a link