So I was following the article by Chet Haase.
Article: https://medium.com/androiddevelopers/navigating-with-deep-links-910a4a6588c
In this, he explains how to work with deep links with navigation components. The pinned shortcut builder needs an Intent but the findNavController helper method returns an object of PendingIntent.
The method from the article to get the pendingIntent.
val pendingIntent = navController
.createDeepLink()
.setDestination(R.id.donutEntryDialogFragment)
.setArguments(arg)
.createPendingIntent()
The ShortcutInfoBuilder method
val pinShortcutBuilder = ShortcutInfo.Builder(
requireContext(),
"id"
)
pinShortcutBuilder
.setShortLabel("someLabel")
.setIntent(intent) // takes an object of Intent
So, how to create the pinned shortcut?
We create the deep links using URIs, and one of the parameters of the Intent constructor is URI. We can directly pass the URI to the constructor and set the activity as the MainActity(because of the single activity paradigm).
Now use the same URI in the fragment which you want to open.
Now stitching everything up,
EDIT
Android shortcut documentation: https://developer.android.com/guide/topics/ui/shortcuts/creating-shortcuts