1

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.

Sudhir Singh Khanger
  • 1,598
  • 2
  • 17
  • 34

1 Answers1

1

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")

beigirad
  • 4,986
  • 2
  • 29
  • 52
  • What do you mean by reset? Won't settings modified graph reset the original graph dynamically. I suppose this piece of code should be added as soon as I can get the instance of navigation component. – Sudhir Singh Khanger Mar 01 '22 at 18:04
  • @SudhirSinghKhanger I had a mistake and I edited my answer. Defining deep-link doesn't need to reset the graph. – beigirad Mar 02 '22 at 14:41
  • Thank you for replying. It works like charm. Do you know if there is an easier way to find nodes which are referenced via `include` tag? As in I call findNode on root graph but it could also find it in one of the included graphs. Currently I have to find the included Nav Graph and then find the node. – Sudhir Singh Khanger Mar 03 '22 at 02:49