Deep Linking And App links with Android

Abhishek Srivastava
7 min readNov 5, 2022

What is deep linking?

Deep links are a type of link that send users directly to an app instead of a website or a App(if already installed). They are used to send users straight to specific in-app locations, saving users the time and energy locating a particular page themselves — significantly improving the user experience.

Deep linking does this by specifying a custom URL scheme (iOS Universal Links) or an Deep Links/intent URL (on Android devices) that opens your app if it’s already installed. Deep links can also be set to direct users to specific events or pages, which could tie into campaigns that you may want to run. Unfortunately It works only on on Android 6.0 (API level 23) and higher.

Benefit of Deep linking

  • Secure: Universal/App Links use HTTPS URLs that link to a website domain that you own, ensuring that no other app can use your links.
  • Seamless experience: One URL works for both your website and app, ensuring that users can successfully access the content they’re looking for without errors.
  • Increase Engagement: Links can be opened from email clients, search engine results, and more.

Developer support required for deep linking

Deep links aren’t automatically set up when you create your app, and they work differently on iOS and Android. Your app development team needs to make changes in the app, and if you implement App Links (Android) or Universal Links (iOS), add a Digital Asset Link JSON file to your website so that users can be diverted to the app when they have installed it. If you implement App Links or Universal Links, this won’t change the web URLs. However, this will allow web campaigns like Search, Shopping, and Display campaigns to take users directly to apps, if installed.

Why are deep links important?

Deep links produce a seamless user journey that reduces churn and increases the likelihood of an install. They let you make sophisticated campaigns while providing a better user experience, moving users onto your app in a single click.

Deep links also create the opportunity for easier incentivization. It’s simple to persuade people to try a new experience when a potential prize or offer is sent to them via a retargeting campaign. For example, let’s say you have a music app and want to promote a new album, so you allocate budget to be spent on a popular website. However, you want the user to listen to the sample in-app, not just on the website (where they are only exposed to the album cover). Here you need a deep link to send them directly to the correct page in your app, offering a seamless user experience.

What is the difference between deep links and app links?

App Links are just deep links that have been verified for a website, AND allows opening URLs in the associated app directly without asking the user to select the app (via the disambiguation dialog). With App Links, your app designates itself as the default handler of a given type of link (though the user can override it from device system settings).

A nice overview of the differences is at https://developer.android.com/training/app-links/verify-site-associations?authuser=0

Also see comparison table below.

The Building Blocks of Deep Links

Deep Link consists of several components, just like any URL. Let’s understand the components of a deep link with an example. Consider a dummy deep link https://abhiappmobiledeveloper.medium.com/?source=topics_v2. It can be categorized into:

  • https — It identifies the protocol used to access the resource on the internet.
  • abhiappmobiledeveloper.medium.com — It is the host, i.e. the domain name or address of the web server that is being accessed.
  • /source— It is the path that specifies a particular page of the content.
  • topics_v2— The query parameter to extract from intents in your destination. topics_v2 is the value of the parameter.

Types of Deep Links

Deep Links can be classified as Default, Deferred, and Contextual deep links.

1. Default Deep Links

These deep links function only to direct users to the required app if it’s already installed on the device. In case, where the app is not installed, the link is unable to reach the endpoint of an app, and thus an error message is displayed.

2. Deferred Deep Links

These deep links are more complex than default deep links. They can direct users to the App if it is available on the device. In case the app is not available on the device, it directs the users to Play Store or to another location, such as the app’s website for more information, and then open the original page that the user was directed to.

3. Contextual Deep Linking

Contextual deep linking involves links that ostensibly provide additional benefits. Contextual deep links are the usual default or deferred deep links with added parameters. Contextual deep links don’t exist by themselves, since the additional parameters are manually added. The parameters can be added by the marketers themselves. Such contextual deep links help in tracking the traffic source of the campaign.

Handle deep links in your Android App

Deep linking is a custom linking URL that gives the developers the freedom to decide what the URL can do when the user clicks on a Custom URL.

In deep linking, you are allowed to set Custom URL schemes like https://abhiappmobiledeveloper.medium.com. For example, the URL https://abhiappmobiledeveloper.medium.com/?source=topics_v2(where topics_v2is the publish ID of an FAQ), will open up the relevant FAQ .

For Example:

//AndroidManifest.xml
<activity android:name=".MainActivity">
<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:scheme="https" android:host="abhiappmobiledeveloper.medium.com"/>
</intent-filter>
</activity>
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView=findViewById<TextView>(R.id.text)
val action: String? = intent?.action
val data: Uri? = intent?.data

data?.let {
textView.text= "Deep link received - " + data
}

}
}

Note:- From Android 12(API level 31) Above approach will not work and will always open non-verified links in the default browser. Starting with Android 12, verified links now automatically open in the corresponding apps for a more streamlined and faster user experience. Google has also changed the default handing of links that aren’t verified through Android App Links or manually approved by the user. Google says Android 12 will always open such non-verified links in the default browser instead of showing you the app selection dialogue.

If you’re an app developer and want to learn about how to add verified links to your app, check out Google’s official documentation. Google first introduced this new behavior in Android 12 Developer Preview 3. However, the option to manually add links wasn’t working at the time.

To learn more about other compatibility changes in Android 12, be sure to check out the Android Dev Summit session linked below.

How to integrate Deep links on Android 12 and Above

Step 1: update all intent filters that can respond to an HTTP link with the android:autoVerify=”true”

<activity
android:name="com.example.MainActivity">
<intent-filter android:autoVerify="true">
// Rest will be same as above implementation
</intent-filter>
</activity>

Step 2: Create the assetlinks.json file and update your package and sha key

//update package_name and sha256_cert_fingerprints with yours
[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "Your App’s package name",
"sha256_cert_fingerprints": ["Your App’s SHA256 finger print"]
}
}]

Step 3: Publishing the JSON verification file Work with your infrastructure team to deploy the assetlinks.json file to the host

https://your domain.com/.well-known/assetlinks.json

Be sure of the following:

  • The assetlinks.json file is served with content-type application/json.
  • The assetlinks.json file must be accessible over an HTTPS connection, regardless of whether your app’s intent filters declare HTTPS as the data scheme.
  • The assetlinks.json file must be accessible without any redirects (no 301 or 302 redirects).
  • Do not publish your app with dev/test URLs in the manifest file that may not be accessible to the public (such as any that are accessible only with a VPN). A work-around in such cases is to configure build variants to generate a different manifest file for dev builds.

To read full story for Deep links, Click here or read the Android official documentation.

Thanks for reading and support.

--

--

Abhishek Srivastava

Senior Software Engineer | Android | Java | Kotlin | Xamarin Native Android | Flutter | Go