Deep linking in Android — Part 1

Image Courtesy-

You: Hey Gagan, I know jack squat about deep linking. Can you please help me out ?
Me: Want to open your app on clicking a URL ? Yes, with deep linking it’s possible. You don’t have to touch the app icon from home screen of your mobile. The app will automatically be launched on clicking a URL. It also allows you to pass the data from URL to app(also known as query params).

As per the official documentation on android developer’s page:

When a clicked link or programmatic request invokes a web URI intent, the Android system tries each of the following actions, in sequential order, until the request succeeds:

- Open the user’s preferred app that can handle the URI, if one is designated

- Open the only available app that can handle the URI

- Allow the user to select an app from a dialog

We need to add intent filters in our app to handle incoming links with the following attributes and elements:
<action>, <data> and <category>. These will let the system know our app can also handle particular type URL’s.

You : Wait ! What ? Particular type of URL’s ? What do you mean by that ?
Me: I meant you will have to mention the scheme, host and pathPrefix in your <data> tag. See the example below:

Above example will only handle

You: Well, this looks easy. Is there a way to handle multiple URL’s from the same app ?
Me: Yes, you can do that. You can also add multiple <intent -filter> tags to handle multiple URL’s. You can also add multiple <data> tags in your <intent-filter>(See below example) but it is considered a good practice to mention separate <intent-filter> tags as it enhances readability and clearly explains the intent behind it.

It will now handle and

You: Yeah ! I am starting to feel a little confident about it. Wait, you also mentioned something about passing data from URL to app. How about that ?
Me: Yeah right, we can do that as well. Below is the sample URL with dummy data passed along with it:

Now we need to handle it in our activity’s onCreate() method. Just add these lines after setContentView()

You: Thanks a lot Gagan. I feel a lot better now.

Me: Bonus tip- You can have custom schemes as well like abc in place of http or https. See below example for this URL- abc://

That’s all. I tried to make this tutorial a little interesting. Hit applaud if you found it helpful.

Cheers !!!

More tutorials in the series:

  1. Deep Linking in Android — Part 1 [Current]
  2. Deep Linking in Android — Part 2

I have created an audio recorder application in Android and I welcome everyone who is reading this post to contribute in any way you can. There is a lot of scope for improvement in this project for both Developers and QA Engineers. You can start by downloading the apk from play store and start exploring. The link is given below:



Don’t forget to check out my other posts. To read them, click here.

Google Certified Associate Android Developer

The (retired) Pub(lication) for Android & Tech, focused on Development