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.
The updated manifest provides the following new tags:
|<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.|
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.
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.
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.
Frequently Asked Questions