Skip to main content

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
)
ParameterTypeRequiredDefaultDescription
contextContextYesAndroid application context
appIdStringYesYour app ID from the OpenLynk dashboard
apiKeyStringYesYour API key (format: ol_...)
baseURLStringNo"https://openlynk.io"API base URL
configOpenlynkSDKConfigNoOpenlynkSDKConfig()SDK configuration options

Methods

All methods are callback-based using Result types.

MethodCallback TypeDescription
init(completion)(Result<Unit>) -> UnitInitialize the SDK, send heartbeat, restore pending links
handleIncomingUri(uri, completion)(Result<ParsedDeepLink>) -> UnitParse an incoming App Link URI
parseDeepLink(uri, callback)(Result<ParsedDeepLink>) -> UnitParse a deep link URI manually
createLink(destination, metadata, callback)(Result<CreatedLink>) -> UnitCreate a shareable deep link
restorePendingLinks(userEmail, callback)(Result<List<RestoredLink>>) -> UnitRestore deferred links by email
restorePendingLinksForAnonymous(callback)(Result<List<RestoredLink>>) -> UnitRestore deferred links using device fingerprint
getLinkBySlug(slug, hostname, callback)(Result<LinkDetails>) -> UnitFetch 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,
)
PropertyTypeDefaultDescription
autoRestoreOnInitBooleantrueAutomatically restore pending links when init() is called
userEmailProvidersuspend () -> String?nullSuspending function that returns the current user's email
onRestoredLinks(List<RestoredLink>) -> UnitnullCallback invoked when deferred links are restored
onDeepLink(ParsedDeepLink) -> UnitnullCallback 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
}
}
}
}

What's Next?