You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Jetpack Compose Navigation从其他应用打开文件并跳转指定页面?

问题:通过外部应用打开文件时,Jetpack Compose Navigation DeepLink无法自动导航到指定页面

我已经在应用Manifest中配置了intent-filters,应用可以从其他文件浏览器/资源管理器应用中被打开,MainActivity中能正确获取到唤起的Intent信息:

class MainActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        Timber.d("intent onCreate ${intent.action} ${intent.data}")
        
        // 打印内容为 "intent onCreate android.intent.action.VIEW 
        // content://com.speedsoftware.rootexplorer.fileprovider/root/storage/emulated/0/Download/test.png"
    }
}

但我希望通过其他应用打开文件时,Jetpack Compose能自动导航到AddNewFileRoute页面,以下配置并未生效:

data object AddNewFileRoute

fun NavGraphBuilder.addNewFileScreen(
    onBackClick: () -> Unit
) {
    composable<AddNewFileRoute>(
        deepLinks = listOf(
            navDeepLink {
                uriPattern = "content://" // 也尝试过 "content://*"
                mimeType = "*/*"
                action = Intent.ACTION_VIEW
            },
            navDeepLink {
                uriPattern = "file://"
                mimeType = "*/*"
                action = Intent.ACTION_VIEW
            }
        )
    ) {
        AddNewFileScreen(
            onBackClick = onBackClick
        )
    }
}

应用会被正常打开,但停留在起始页面(HomeRoute)。

使用的Navigation库版本:

androidxNavigation = "2.8.9"

如果为特定外部文件指定硬编码的完整路径,DeepLink配置可以正常生效:

uriPattern = "content://com.speedsoftware.rootexplorer.fileprovider/root/storage/emulated/0/Download/test.png"

内容的提问来源于stack exchange,提问作者user924

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 13:25:55