How To Setup Deferred Deep Linking on Android

In the world of mobile apps, optimizing the customer journey is crucial. Deferred deep linking offers a powerful way to guide users seamlessly to specific in-app content, enhancing both functionality and user experience. By setting up deferred deep linking, mobile marketers can ensure that even first-time users land on the exact page they need — whether it’s a personalized onboarding screen, a promotional offer, or another targeted page.

Whether you’re interested in creating the best customer experience, improving your marketing campaign, unlocking the full potential of your app for new users, or reengaging existing users in meaningful ways, deferred deep linking can support many types of optimization.

This guide covers everything you need to know to get started with deferred deep linking on Android.

Looking to set up deferred deep links on Apple iOS? Check out our other guide.

Now, let’s examine how to actually set up deferred deep links on Android using Branch.

Step 1

Add the Branch SDK to your project by opening your build.gradle (app-level) file and adding the following dependency, then syncing the project file with Gradle:

implementation ‘io.branch.sdk.android:library:5.+’

Note: As of version 4.3.0, Google’s Play Install Referrer Library is bundled into the Branch Android SDK. Install Referrers are mechanisms to support deterministic matching on Android devices when downloading apps through specific app stores. When Branch is 100% confident in its attribution accuracy, the deep link data will contain the variable +match_guaranteed=true. Branch supports Huawei, Xiaomi, and Samsung App Stores once you explicitly add the dependencies to the Gradle file.

Step 2

Configure the Android Manifest file. Ensure the Launcher Activity is set to singleTask to handle incoming intents properly.

android:name=”.LauncherActivity”
android:launchMode=”singleTask”
android:label=”@string/app_name”
android:theme=”@style/AppTheme.NoActionBar”
android:exported=”true”>

Then, add the relevant intent filters for Branch URI schemes and App Links (app.links).

Note: If you’re using a custom domain, you’ll need to add an additional intent filter specifically for that custom domain.

Branch URI scheme intent filter:

<!– Branch URI Scheme –>

<intent-filter>

<!– If utilizing $deeplink_path please explicitly declare your hosts, or utilize a wildcard(*) –>

<!– REPLACE `android:scheme` with your Android URI scheme –>

<data android:scheme=”yourapp” android:host=”open” />

<action android:name=”android.intent.action.VIEW” />

<category android:name=”android.intent.category.DEFAULT” />

<category android:name=”android.intent.category.BROWSABLE” />

</intent-filter>

Next, add the relevant key_live & key_test from the Branch Dashboard and set the SDK TestMode to “true” if using a test instance, or “live” for production release.

<!– Branch App Links – Live App –>

<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” />

<!– REPLACE `android:host` with your `app.link` domain –>

<data android:scheme=”https” android:host=”example.app.link” />

<!– REPLACE `android:host` with your `-alternate` domain (required for proper functioning of App Links and Deepviews) –>

<data android:scheme=”https” android:host=”example-alternate.app.link” />

</intent-filter>


<!– Branch App Links – Test App –>

<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:scheme=”https” android:host=”example.test-app.link” />

<!– REPLACE `android:host` with your `-alternate` domain (required for proper functioning of App Links and Deepviews) –>

<data android:scheme=”https” android:host=”example-alternate.test-app.link” />

</intent-filter>

</activity>

Next, add the relevant key_live & key_test from the Branch Dashboard and set the SDK TestMode to “true” if using a test instance, or “live” for production release.

<!– Branch init –>

<!– REPLACE `BranchKey` with the value from your Branch Dashboard –>

<meta-data android:name=”io.branch.sdk.BranchKey” android:value=”key_live_XXX” />

<!– REPLACE `BranchKey.test` with the value from your Branch Dashboard –>

<meta-data android:name=”io.branch.sdk.BranchKey.test” android:value=”key_test_XXX” />

<!– Set to `true` to use `BranchKey.test` –>

<meta-data android:name=”io.branch.sdk.TestMode” android:value=”false” />

Step 3

Within the Application class, import Branch via io.branch.referral.Branch and call Branch.getAutoInstance(this), which is the singleton method to return the pre-initialized object of the type Branch.

import io.branch.referral.Branch

class CustomApplicationClass : Application() {

override fun onCreate() {

super.onCreate()

// Branch logging for debugging
Branch.enableLogging()

// Branch object initialization
Branch.getAutoInstance(this)

}

}

Step 4

Finally, initialize Branch within the onStart() of the Main Activity or Custom Activity.

Once the SDK is properly initialized with a Branch-referred link click, retrieve the parameter payload within the callback of the Branch.sessionBuilder() to deep link the user to the right page.

Note: Initializing Branch in other Android lifecycle methods, such as onCreate() or onResume(), will lead to unintended behavior. The onStart() method is what makes the Activity visible to the user, as the app prepares for the Activity to enter the foreground and become interactive.

override fun onStart() {

super.onStart()

Branch.sessionBuilder(this).withCallback {params, error ->

if (error != null) {

Log.e(“BranchSDK_Tester”, “branch init failed. Caused by -” + error.message)

} else {

Log.i(“BranchSDK_Tester”, “branch init complete!”)

// Print params for deep link payload

}

}.withData(this.intent.data).init()

}

You’re done!

Now you can start using deferred deep links on Android. If you run into any issues or have additional questions, reach out to our team.

For even more information on deep linking, download our Dive Into Deep Linking guide.