How to use Deeplinks in Android


Hi folks, in this blog, we will try to learn what deep links are and how to use them in Android.

What is a Deeplink ?

Deep links are links that take users directly to an app rather than visiting a website. They are used to take the user to a particular in-app destination. It saves them time and energy in the process of locating a specific page. As a result, it considerably increases the user experience.

It helps apps to function the way the web does, in the sense of connectivity of the web. We click any link on the web, an app, in an email or SMS it can directly take us to the specific screen in the app. Deeplinks can also send data to the app, like a unique identifier.

Deferred Deep Links

Deferred deep links are a form of deep links that functions even if the app does not exist in the user’s device. In this scenario, the user can be deferred to the PlayStore or the AppStore. After installing the app, the user can be taken to a specific location within the app.

Implementation in Android

Whenever a link is clicked, the android system tries the following actions –

  1. If one is specified, open the user’s chosen app that can handle the URI.
  2. Open the only application that can deal with the URI.
  3. Allow the user to choose an app from a drop-down menu.

We can follow the steps down below to create a Deeplink for an app

  1. Firstly we have to create an intent filter in our manifest file.
  2. Secondly we have to add an <action> element in it. We have to specify ACTION_VIEW intent action which helps the intent filter to be searched from Google.
  3. Thirdly we have a <data> element which represents a URI format that would lead to the activity. It should include the android:scheme attribute.
  4. Lastly, a <category> element is to be added. The BROWSABLE category is required for the intent filter to be accessed from the web. DEFAULT category is also needed, otherwise activity can be started only if the intent specifies our app component name.

We can create a sample application to implement a basic deep link.

The below XML snippet is an example of an intent filter in our manifest for deep linking.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.sampledeeplinkproj">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/Theme.SampleDeepLinkProj">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <!-- Accepts URIs that begin with "http://www.example.com/samepldeeplink" -->
                <data android:scheme="http"
                      android:host="www.example.com"
                      android:pathPrefix="/sampledeeplink"/>
            </intent-filter>
        </activity>
    </application>

</manifest>

Now that we added the intent filters with URIs, Android is able to route any Intent that has matching URIs.

I hope this blog helped you learn and understand what deep links are and how they can be used to improve users’ app experience.

Leave A Comment

Your email address will not be published. Required fields are marked *