我们有一个利用Deeplinks的应用程序。我们还使用Android导航组件。
当前,我们在out navigation.xml文件中配置Deeplink,这可以正常工作,但是现在我们需要能够在构建时基于设置的环境变量添加另一个Deeplink。
当前,我们以以下形式在out navigation.xml文件中配置Deeplinks:
<deepLink
android:autoVerify="true"
app:uri="foo.bar.baz/pull/{quxArg}/{quuxArg}" />
现在,我们需要能够在构建时基于一组Envar创建其他Deeplink。
示例:
DEEPLINK_ENVAR = "replacement.com"
Build.gradle:
manifestPlaceholders = [deeplink:DEEPLINK_ENVAR]
navigation.xml:
<deepLink
android:autoVerify="true"
app:uri="${deeplink}/pull/{quxArg}/{quuxArg}" />
请注意,以上操作无效。
如果这只是Manifest中的 Intent 过滤器,我们可以使用Manifest占位符来完成此任务,并将其设置在app.gradle中。但是,navigation.xml中设置的Deeplinks将解析为URI,并在替换掉它们之前销毁所有占位符。
有没有人尝试过类似的东西?我试图避免必须运行预构建脚本来直接对导航文件进行模板化。
所需结果:
我希望能够在使用Android导航组件的同时在构建时添加一个附加的Deeplink(实际上是4个到不同的目的地)。
最佳答案
不知道我是否完全理解,但是...
您应该能够将多个DeepLink添加到一个 Action 中。
如果需要它重定向到另一个 fragment ,则可以尝试使用“deepLinkTokenCheckFragment”之类的方法,该方法可以接收DeepLink,然后从中提取信息,并可以将用户重定向到您希望他们访问的页面。
我有一个执行此类操作的应用程序
private fun extractAction() {
if (ACTION_VIEW == parent.intent.action) {
// Collect information to know where to redirect here.....
val actionType = parent.intent.data
?.toString()
?.substringBefore('?')
?.substringAfterLast('/')
action = get information or token from the url here //?.substringBefore('?') ?.substringAfterLast('/')
when (action) {
"change_password" -> go to change password screen
"change email" -> go to change email screen
"go to other" -> go to other screen
}
}
}
这只是我做事的一个想法。
以同样的方式,您可以检查构建或与其进行比较的任何内容,而不是检查某些 token 。