android - 使用 Jetpack Navigation 在深度链接 URI 中使用字符串常量

标签 android android-architecture-navigation android-navigation android-jetpack-navigation android-deep-link

是否可以在深层链接 URI 中使用字符串常量?

目前我有几个链接,导致host部分重复:

<deepLink app:uri="www.host.com/a" />
<deepLink app:uri="www.host.com/b" />
<deepLink app:uri="www.host.com/c" />
<deepLink app:uri="www.host.com/d" />

因此,我正在寻找一种以某种方式提取 www.host.com 的方法。

我一直天真地尝试将它提取到 strings.xml:

<string name="host">www.host.com</string>

然后:

<deepLink app:uri="{@string/host}/details/{id}" />

但这不起作用(在深度链接 URI 主机中不正确使用通配符和/或占位符 编译错误)

最佳答案

如对此问题的评论中所述 OP想在深层链接 uri 中使用常量字符串进行多次使用。名为 Entity declaration 的 XML 功能允许这样做。

也回答了具有类似目标的问题here .

关于android - 使用 Jetpack Navigation 在深度链接 URI 中使用字符串常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63244073/

相关文章:

Android TCP 紧急消息实现

android - kotlin 中的 Parcelable 对象中的 ArrayList<ArrayList<String>>

java - 如何修复(错误 : cannot find symbol class ActionOnlyNavDirections) with navigation architecture in Android studio

Android Jetpack 导航组件问题,以启动 fragment 作为根目标

android - 如何在 Android 中打开/关闭抽屉导航后立即刷新列表

java - 在等待退出信号时处理InterruptedException(Android中的错误?)

android - 由于未接受某些许可证,无法安装以下 Android SDK 包

android - 使用 PopUpTo 导航但不知道您的根目的地是什么 - 导航架构组件

android - 使用单个 NavHostFragment 导航具有多个模块的应用程序

android - 支持导航组件的隐式和显式深度链接