Is there any guidance for how to do deeplinks from...
# compose-wear
y
Is there any guidance for how to do deeplinks from a Complication to a Wear Navigation app?
I'm building a launch action and setting an arbitrary key that I look for later. But it feels strange.
Copy code
private fun collectionLauncher(collectionId: Int) = ActionBuilders.LaunchAction.Builder()
        .setAndroidActivity(
            AndroidActivity.Builder()
                .setClassName(MediaActivity::class.java.name)
                .setPackageName(this.packageName)
                .addKeyToExtraMapping(
                    "collection", AndroidIntExtra.Builder()
                    .setValue(collectionId)
                    .build()
                )
                .build()
        )
        .build()
In my composable with the NavScaffold I'm then looking for it.
Copy code
LaunchedEffect(key1 = Unit) {
                if (intent?.hasExtra("collection") == true) {
                    val collectionId = intent.getIntExtra("collection", -1).toString()
                    intent.removeExtra("collection")
                    navController.navigateToCollection(collectionId)
                }
            }
a
I do something similar like this, lemme dig it up
👍🏻 1
message has been deleted
I use a stripped down version of voyager, it’s a mix of that and react-navigation
I wish there was a cleaner way to utilize when and intent extras
1
b
I am using NavDeepLinkRequest because of bundle. It is to create a NavDeepLinkRequest and execute navigation through matchDeepLink, which may be used in your case. This is a temp code.
Copy code
fun NavHostController.navigate(
    args: Bundle,
    navOptions: NavOptions? = null,
    navigatorExtras: Navigator.Extras? = null
) {
    val routeLink = NavDeepLinkRequest
        .Builder
        .fromUri(
            NavDestination.createRoute(
                when (args.getInt("Temp")) {
                    0 -> "route0"
                    1 -> "route1"
                    else -> "route0"
                }
            ).toUri()
        )
        .build()

    val deepLinkMatch = graph.matchDeepLink(routeLink)
    if (deepLinkMatch != null) {
        val destination = deepLinkMatch.destination
        val id = destination.id
        navigate(id, args, navOptions, navigatorExtras)
    } else {
        navigate("route0", navOptions, navigatorExtras)
    }
}
y
Where do the args come from?
In my case its a complication which doesnt support pending intent.
So I only need to solve the receiving it when app starts
b
Oh.. I see. I create a bundle before navigate on lifecycle observers. I'm sorry, It was not match to your case.
y
@yschimke
In my case its a complication which doesn’t support pending intent.
Is this a wear os 3 issue, i used pending intent in wear os 2 in the java
onComplicationUpdate
method, which seems to work fine. Can you forward me doc regarding the pending intent not working in complication?
In wear os 2, i used ComplicationManager following this doc (https://developer.android.com/training/wearables/tiles/exposing-data-complications), but ComplicationManager seems to be deprecated.
y
Oops, you are right. My PR has tiles and complications. So that's fine for complication. But I think I'm still stuck with that for tiles. https://github.com/google/horologist/blob/4e0ce7c138e22125532a921096e278b72387a5fa/media-sample/src/main/java/com/google/android/horologist/mediasample/tile/MediaCollectionsTileService.kt#L65
Copy code
private fun collectionLauncher(collectionId: Int) = ActionBuilders.LaunchAction.Builder()
        .setAndroidActivity(
            AndroidActivity.Builder()
                .setClassName(MediaActivity::class.java.name)
                .setPackageName(this.packageName)
                .addKeyToExtraMapping(
                    "collection", AndroidIntExtra.Builder()
                    .setValue(collectionId)
                    .build()
                )
                .build()
        )
        .build()