Skip to main content

Android SDK Setup

To integrate AppsOnAir-AppLink Android SDK to your Android native Apps with Kotlin, follow the below steps

BETA

The plugin is fully functional and integrates with our AppLink service, which is currently in public beta. While you can start using it today, please note that there may be minor changes or improvements as we prepare for full production launch.

Basic Requirements for Service Usage

apiKey Setup
  • Make sure to configure the API key properly. For additional information Getting started
Prerequisites
  • Install or update Android Studio to its latest version.
  • Make sure that your project meets these requirements:
    • Android Gradle Plugin (AGP): Version 8.0.2 or higher
    • Kotlin: Version 1.7.10 or higher
    • Gradle: Version 8.0 or higher
Newer versions of Android Studio

When creating a new project from Android Studio Artic Fox (or newer) the allprojects{...} is no longer added in the project level gradle.so need add in settings.gradle

settings.gradle

dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Docusaurus logo

gradle.properties
android.useAndroidX = true
android.enableJetifier = true

Open Your Root build.gradle File and Add the Following

build.gradle

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Add the Following to Your dependencies Section

libs.versions.toml
    [versions]
appsonairAndroidApplink = "Tag" // latest version

[libraries]
appsonair-android-applink = { module = "com.github.apps-on-air:AppsOnAir-Android-AppLink", version.ref = "appsonairAndroidApplink" }
app/build.gradle
    dependencies {
implementation(libs.appsonair.android.applink)
}

Docusaurus logo

Sync Gradle

Make sure to press "Sync Now" on the banner that pops up after saving!

Add Required Code

  • Add below code to the app's AndroidManifest.xml file under the activity tag of your main activity.
AndroidManifest.xml
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="your domain"
android:scheme="https" />
</intent-filter>
  • Add below code if you are using custom uri scheme.
AndroidManifest.xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="open"
android:scheme="your scheme" />
</intent-filter>

To initialize the AppLink we recommend adding the initialization code within the onCreate method of your Main Launcher Activity (MainActivity).

MainActivity.kt
import com.appsonair.applink.interfaces.AppLinkListener
import com.appsonair.applink.services.AppLinkService

class MainActivity : AppCompatActivity() {
private val TAG = "MainActivity"
private lateinit var deepLinkService: AppLinkService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Initialize deepLink service and set listener for deep link and referral link events
deepLinkService = AppLinkService.getInstance(this)
// Initialize the AppLink to track the deepLink
deepLinkService.initialize(this, intent, object : AppLinkListener {
override fun onDeepLinkProcessed(uri: Uri, result: JSONObject) {
// Store the processed deep link URL and log the parameters
}

override fun onDeepLinkError(uri: Uri?, error: String) {
// Handle error when deep link processing fails
}
})
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
deepLinkService.handleDeepLink(
intent,
"com.example.appsonair_android_applink"
)
}
}
  • The initialize() function initializes the common AppLink service and sets up the deep link handler. It processes the incoming link when the app is launched with an intent and uses an AppLinkListener to handle the success or failure of deep link processing.

To create the AppLink, you can call the createAppLink method inside an onClick listener or wherever you need it.

MainActivity.kt
import com.appsonair.applink.services.AppLinkService

class MainActivity : AppCompatActivity() {
private val TAG = "MainActivity"
private lateinit var deepLinkService: AppLinkService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Initialize deepLink service and set listener for deep link and referral link events
deepLinkService = AppLinkService.getInstance(this)
val socialMeta = mapOf(
"title" to "link title",
"description" to "link description",
"imageUrl" to "https://image.png"
)

// Create the AppLink
val result = deepLinkService.createAppLink(
name = "AppsOnAir",
url = "https://appsonair.com",
urlPrefix = "YOUR_DOMAIN_NAME", //shouldn't contain http or https
shortId = "LINK_ID",
socialMeta = socialMeta,
androidFallbackUrl = "www.playstore/app.com",
iOSFallbackUrl = "www.appstore/app.com",
)
}
}

AppLinkParams Properties

Defines all parameters used to construct a AppLink, including app URL, fallbacks, short ID, and social-meta.

KeyDescription
urlThe actual deep link URL that the app should open. Example: myapp://product/123
nameThe name or label for the link, often used for internal identification.
urlPrefixThe base URL prefix for the link (e.g., https://app.domain.com/). This helps create a complete shareable link.
androidFallbackUrlA web URL to redirect users to when the app is not installed on Android devices.
iOSFallbackUrlA web URL to redirect users to when the app is not installed on iOS devices.
shortIdAn optional short ID to make the link shorter and easier to share. If provided, the final link becomes urlPrefix/shortId
socialMetaMeta information used for social sharing previews. refer SocialMeta Properties
isOpenInBrowserAppleDetermines whether the link should open in the browser on Apple devices (iOS/macOS).
isOpenInIosAppSpecifies if the link should open in the iOS app even if your app is installed.
isOpenInAndroidAppIndicates whether to open the link in the Android app even if your app is installed.
isOpenInBrowserAndroidDetermines if the link should open in the browser on Android devices.

socialMeta Properties

KeyDescription
titleThe title to show in social media link previews.
descriptionA short description used in social sharing cards (Facebook, Twitter, etc.).
imageUrlA URL to an image that will appear in the social media preview.

To get the AppLink referral information, you can call the getReferralDetails() method on onCreate, onClick or wherever you need it.

MainActivity.kt
import com.appsonair.applink.services.AppLinkService

class MainActivity : AppCompatActivity() {
private val TAG = "MainActivity"
private lateinit var deepLinkService: AppLinkService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

// Initialize deepLink service and set listener for deep link and referral link events
deepLinkService = AppLinkService.getInstance(this)
// Get the referral information
val referral = deepLinkService.getReferralDetails()
}
}
  • getReferralDetails() is used for get the latest referral information.
Response
{
"data": {
"shortId": "linkId",
"referralLink": "https://your.referral.link"
}
}

Run your app by using Android Studio on Android simulators or any physical device to make sure it builds correctly.

For more details explore the example