https://kotlinlang.org logo
#compose
Title
# compose
j

John Aoussou

11/29/2021, 3:17 PM
Is there a way to call a specific composable from a notification? I know how the open an activity, but I'm trying to access a specific screen (the same way you would do it with a navhost)
l

louiscad

11/29/2021, 3:32 PM
Yes there's two ways. Deep links (which also discard all previous UI state), or calling the navigator, I have a draft article on that latter approach if that suits your use case better than deep links.
j

John Aoussou

11/29/2021, 4:11 PM
@louiscad I did find a couple or resources using deeplinks, but I'm not sure how to create them in my case, that's how my navigator looks like
Copy code
@Composable
fun Navigation(){
    
    val navController = rememberNavController()
    val uri = "excerpts"
    
    NavHost(navController = navController, startDestination = Screen.Home.route ){

        composable(route = Screen.Home.route){ HomeScreen(navController)}

        composable(route = Screen.DayCardFull.route){ DayCardFullScreen()}

        composable(route = Screen.Settings.route){ SettingsScreen() }



    }
    
}
I'm trying to open SettingsScreen from the notification.
Looking forward to read the article about the other method!
l

louiscad

11/29/2021, 4:13 PM
Creating a deep link is not relying on Compose APIs FYI
j

John Aoussou

11/29/2021, 4:21 PM
Yes, I think I do get that. I tried to mimic this article, but in my case there is no"id", so I don't understand how to adapt i to my case. https://proandroiddev.com/open-composables-via-notification-with-jetpack-navigation-b922384f4091
i

Ian Lake

11/29/2021, 6:25 PM
What makes you think any kind of ID is required? Just leave it out if you don't need it
j

John Aoussou

11/30/2021, 2:38 PM
@louiscad I got it to work using deeplinks. However, it seems like the uri has to be in the "https..." format, which in my case is confusing because everything is running locally (I'm using a fake url now). Please ping when you publish your article about the navigator method.
i

Ian Lake

11/30/2021, 6:02 PM
You can use whatever deep link you want, as long as it is a valid Uri excerpts://nav/day would be a valid deep link. Note that the intent filter part is also completely optional - your Intent can specify exactly what ComponentName you want (i.e., what activity)
🙇‍♂️ 1
👍 1
10 Views