I'm trying to enable my app to open and read .txt files when users tap on them. Ideally, the user would see my app listed in the system's 'Open With' popup upon tapping the file. Once they choose my app, I need to retrieve the URI path of the selected file and pass it as an argument to a navigation composable. Unfortunately, despite my efforts, I've only found deep linking methods suitable for web links so far.
How to implement this with jetpack compose deeplinking? I would be grateful for any code snippet, suggestions, references, or links.
Here is my code
Manifest file
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data android:scheme="content" />
</intent-filter>
Navigation
NavHost(
navController = navController,
startDestination = Screen.HomeScreen.route
) {
composable(
route = Screen.HomeScreen.route.plus("?project={projectPath}"),
deepLinks = listOf(
navDeepLink {
uriPattern = "file://{project}"
mimeType = "text/plain"
}),
arguments = listOf(
navArgument("project") {
type = NavType.StringType
defaultValue = ""
}
)
) {
val projectFromDeepLink: String = it.arguments?.getString("project") ?: ""
}
}
This code isn't working perfectly for me. While it successfully lists my app in the 'Open With' popup, I'm unable to obtain the file path after the app is selected.