How to Enable Deep Links On Android

What Are Deep Links?

Android deep links open a specific page within an app and optionally pass data to it. Developers may find deep links particularly useful for actions, such as clicking a notification or sending an app link via email.

Let's take an email client as an example. When the user clicks the notification of an email she received, it opens a deep link that takes her to the email in the app. Last but not least, deep links also allow Google to index your app and link to specific sections of your app in searches. The deep link appears as a search result in Google and can take the user to a particular section of your app.

Implementing Deep Links

To add a deep link to your app, you must add it to your android manifest file as an intent filter. Take a look at the following example.

The <action> and <data> tags are required. The <action> tag chooses what happens in the app when the link is clicked. The <data> tag specifies what URIs are acceptable as deep links to the page.

In the above example, navigating to either http://www.mydeeplink.com or tutsplus://deeplink takes the user to the LinkActivity activity. The <category> tags specify the properties of the deep link. Notice that you need to create a separate intent filter  for each URI scheme and each activity.

You can create multiple links to the same activity. To differentiate these, you need to parse the intent's data in your code to differentiate the links. This is usually done in the onCreate() method by reading in the data and acting accordingly.

Testing Deep Links

Android Studio makes it very easy to test deep links. Click Run > Edit Configurations to edit the configuration of the project.

Testing Deep Links
Testing Deep Links

Open the General tab at the top and enter the URI in the Deep Link field in the Launch Options section. When you launch your app using Android Studio, it will attempt to open the specified URI.

Conclusion

Now that you know how to create and use deep links, you can open up new entry points for users to interact with your app. Users may use Google search on their phones to find pages within your app and you can create notifications that open a specific page in your app when clicked.

Tags:

Comments

Related Articles