Tech Blog

Android, Coding, Programming

How to use Deeplinks in Android

By Aditya Yadav3 min read
← Back to blog

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.

Keep reading

You may be interested in

Browse all articles →
How to extract APK file of installed application in Android programmatically
June 6, 20221 min read

How to extract APK file of installed application in Android programmatically

Step 1 : Get the path of the installed application Step 2 : Store the Apk file in required folder

By Sushant Singh RathoreRead More →
Disable MAC Randomization in Android 10 and above devices
June 1, 20223 min read

Disable MAC Randomization in Android 10 and above devices

Recently we came across an interesting feature, to set static MAC address for the wifi ssids for Android 10 and above devices.MAC Randomization generates a random MAC address for a wifi ssid for the following conditions mentioned below :- When connecting with that particular network for the first time=- Forget and rejoin the network. in […]

By Kumar gauravRead More →
Set up work profile on company owned android 11 and above device
June 1, 20223 min read

Set up work profile on company owned android 11 and above device

Android 11 introduces work profiles for company owned devices with improved support for work profiles. If a work profile is created from a setup wizard using QR code or zero touch enrollment, the device is recognized as Work profile on company owned devices. If a work profile is created using any other method except the […]

By Kumar gauravRead More →