Jetpack Compose Navigation - Passing local file location as string
L

1

7

I am trying to pass audio file location(/storage/emulated/0/Android/media/...) as string from first screenhome_screen to second screendetail_screen, When I pass normally above string as a parameter I am getting this error

java.lang.IllegalArgumentException: Navigation destination that matches request NavDeepLinkRequest{ uri=android-app://androidx.navigation/detail_screen/45193/'/storage/emulated/0/Android/media/com.Slack/Notifications/Slack - Here you go.mp3' } cannot be found in the navigation graph NavGraph(0x0) startDestination={Destination(0x442b361f) route=home_screen}

As for the place, if I am passing a string like Here you go.mp3, it's working fine!

I think Compose Navigation is not able to differentiate between /

Lydie answered 4/7, 2022 at 16:57 Comment(0)
A
10

The routes are parsed as Uris so if you want to send a string that contains special characters, you need to use Uri.encode() before appending them to your route.

Navigation will automatically decode the arguments before delivering them to your destination, so you don't need to do anything to get the original Uri back out.

Alvis answered 4/7, 2022 at 20:47 Comment(1)
This is perfect, thanks a lot @Alvis I think this should be addressed in the official docs of navigation compose to send arguments, since I have been like 1 hour looking at what the issue was, maybe a more verbose exception in the logcat like "Are you trying to send an URL, if so, please use Uri.enconde(string) first before sending as an argument"Antibes

© 2022 - 2024 — McMap. All rights reserved.