Step 6a. Implement Deep-linking in App

Add an intent filter to the manifest

The first step in adding deep links to your app is to update the Android manifest. Do that now. Add a new intent filter to the Activity of your Android manifest file so that the Android operating system knows which deep links your app can handle.

AndroidManifest.xml

image1.png

The updated manifest provides the following new tags:

Tags Description
<intent-filter> Contains the view elements for the RecipeActivity.
<action> Specifies the ACTION_VIEW intent action.
<data> One for each data URI format that the activity accepts. This is the primary mechanism to declare the format for our deep links.
<category>

Used both for BROWSABLE and DEFAULT intent categories:

BROWSABLE -- required for a mobile browser to execute the intent from within Google Search results. Without this attribute, a click on your URL from a mobile browser will not resolve to your app. Instead, the current web browser will open the URL of the website.

DEFAULT -- required only if you want your Android app to respond to a click from any referring website. The intent used from Google search results includes the identity of your app, so the intent explicitly points to your app as the recipient. Other links to your site do not know your app identity, so the DEFAULT category declares your app can accept an implicit intent.

Note: If you have multiple deep link formats (eg. http:// and recipe-app://), you'll need to add an individual intent filter to handle each one.

Add code for the intent filter

With the intent declared for the RecipeActivity, you now need to add the code to the sample app to show a recipe when a deep link intent is received.

First, in the onCreate() method, add a call to onNewIntent() and pass in the intent that was sent to create the current Activity.

RecipeActivity.java

image2.png

Then, define the onNewIntent() method and verify that the Intent is a deep link intent. If it is a deep link intent, extract the recipe URI from the intent data, look it up in the content provider and make a call to the showRecipe() method to display the recipe.

RecipeActivity.java

image3.png

This takes the unique recipe ID in the deep link and looks it up in the local database of the app. If a recipe with that ID is found, the app will show it on the screen.

Important: An app opened via a deep link should provide users with a First Click Free experience. This means that on the first visit to your app, a user should go directly to the relevant content, and not be interrupted with any interstitial content like prompts or login screens. You may prompt the user for an action after the first click. The First Click Free experience must be provided even if the app has never been launched or a user logged in.

Frequently Asked Questions

 

Return to main testing guide

Have more questions? Submit a request

0 Comments

Article is closed for comments.