Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

The Purpose of Deep Links

Here’s a real world example to understand the purpose of deep links. Suppose you’re browsing through a social media app and come across an advertisement for of a pair of shoes you really like and would like to check out further or perhaps even buy. So you click the advertisement, and it takes you to the brand’s webpage or app screen with the product listing and description. You can then simply check the details, select preferred color and size, and proceed to buy the product.

Setting Up Deep Links

The navigation component has support for defining deep links as part of the composable() function that defines a destination in the graph. It takes in a parameter named deepLinks that accepts a list of NavDeepLink objects. You can easily create a NavDeepLink object using the navDeepLink() function defined in the navigation component library.

navDeepLink {
  uriPattern = "https://www.some-ecommerce.com/productId={productId}"
  action = Intent.ACTION_VIEW
}
composable(
  "product-listing-route",
  deepLinks = listOf(navDeepLink {
    uriPattern = "https://www.some-ecommerce.com/productId={productId}"
    action = Intent.ACTION_VIEW
  })
) { ... }
backStackEntry.arguments?.getString("productId")
<activity ...>
  <intent-filter>
    ...
    <data android:scheme="https" android:host="www.some-ecommerce.com" />
  </intent-filter>
</activity>
See forum comments
Download course materials from Github
Previous: Introduction Next: Demo