Search code examples
androiddeep-linkingandroid-architecture-navigationandroid-app-links

Assign Implicit deeplink programmatically


In order to add a deep link implicitly, the deep link has to be added to XML. If I want to check if the destination can handle a deep link or modify it in some way then one added in XML is prohibitive.

I can see there is an addDeepLink but I haven't found a great example of it. If the deep link is added programmatically then is the nav graph even aware of it.


Solution

  • If you have the target destination in your graph, that's enough find it in the graph and add suit deep-link.

    findNavController().graph
          .findNode(R.id.my_destination)
          ?.addDeepLink("hello://world")