Mastering Deep Linking in Android with branch.io

Rajat Dhamija
AppyHigh Blog
Published in
3 min readSep 8, 2020
Deep linking with branch.io

What is a deep link?

In the context of mobile apps, deep linking consists of using a uniform resource identifier (URI) that links to a specific location within a mobile app rather than simply launching the app. Deferred deep linking allows users to deep link to content even if the app is not already installed.

Normally when you click on a link it takes you to a website, the website opens in a browser. Mobile Deep Linking will allow you to navigate users to a your app with some wrapped date inside rather than a particular website.

Implementing deep linking using branch.io

10 Step to get rolling with branch.io

Step 1 : Signup on branch.io

Step 2: Add a brand link that will uniquely identify your app

Step 3: Add identity for your app on setup page

Step 4: Enable App links and add your SHA256 Fingerprint. Link attached for reference to how to get the fingerprint. Also add the URI Scheme that will help branch links to identify your app in you mobile.

Step 5: Add dependency in your android build.gradle file

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation 'io.branch.sdk.android:library:4.+'
}

Step 6: Add the following code to your AndroidManifest.xml inside your launcher activity

<!-- Branch URI scheme -->
<intent-filter>
<data android:scheme="mad4android" 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>

<!-- Branch App Links -->
<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="map4android.app.link" />
</intent-filter>

Step 7: Add this code to AndroidManifest.xml at application level

<!-- Branch init -->
<meta-data android:name="io.branch.sdk.BranchKey" android:value="your_live_key" />
<!-- Branch testing (TestMode "true" to simulate fresh installs on dev environment) -->
<meta-data android:name="io.branch.sdk.TestMode" android:value="false" />

Step 8:
Enable Auto Session Management -> Add this to your custom Application class file:

public final class CustomApplicationClass extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize the Branch object
Branch.getAutoInstance(this);
}
}

Step 9: Starting a branch session:

A Branch session needs to start every single time your app opens. Branch checks to see if the user came from a link and if so, the callback method returns any deep link parameters for that link.

@Override
public void onStart() {
super.onStart();
Branch branch = Branch.getInstance();

// Branch init
branch.initSession(new Branch.BranchReferralInitListener() {
@Override
public void onInitFinished(JSONObject referringParams, BranchError error) {
if (error == null) {
// params are the deep linked params associated with the link that the user clicked -> was re-directed to this app
// params will be empty if no data found
// ... insert custom logic here ...
Log.i("BRANCH SDK", referringParams.toString());
} else {
Log.i("BRANCH SDK", error.getMessage());
}
}
}, this.getIntent().getData(), this);
}

@Override
public void onNewIntent(Intent intent) {
this.setIntent(intent);
}

Step 10: Check the Integration Status on the dashboard after running the app to check of the app is successfully configured

Liked my work? Buy me a coffee.

--

--