我可以使用String资源在Jetpack导航XML文件中生成深度链接吗?

问题描述

假设我的Gradle文件中有以下{ label: 'Update Time',name: 'UPD_DT',formatter: 'date',formatoptions: { srcformat: 'd-M-y H:i:s',newformat: 'd-M-Y h:i:s' },width: 400 },部分:

buildType

我想使用生成的String资源作为Jetpack导航XML文件中的深层链接,如下所示:

buildTypes {
    debug {
        ...
        resValue "string","DEEPLINK_EXAMPLE","appnamedebug://detail/{detail_id}"
        ...
    }
    release {
        ...
        resValue "string","appname://detail/{detail_id}"
        ...
    }
  }

我尝试过类似的操作,但是当我查看<deepLink app:uri="@string/DEEPLINK_EXAMPLE" /> 输出文件时,没有显示“意图过滤器”。

这甚至有可能吗?如果是的话,有什么我想念的吗?

解决方法

问题中的方法只会导致清单具有如下意图过滤器:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:scheme="http" />
    <data android:scheme="https" />
    <data android:host="string" />
    <data android:path="/DEEPLINK_EXAMPLE" />
</intent-filter>

我想那是个白日梦。

好吧,最后,我不得不求助于以前的方法:将导航图复制到调试和发布源集,并在其中相应地设置Deeplink URI。

因此debug源集中的导航图将具有以下内容:

<deepLink app:uri="appnamedebug://detail/{detail_id}" />

release源集中的导航图将具有以下内容:

<deepLink app:uri="appname://detail/{detail_id}" />

我实际上不确定是将导航图保留在main源代码中还是将其删除,以便debug / release源集中的导航图优先。 / p>

,

据我所知,这是不可能的。

上一个答案说明了所有内容,但为清楚起见,我想添加以下示例:

如果您添加到nav_graph

<deepLink
    android:id="@+id/myLink"
    app:uri="@string/my_link_uri"
/>

它将在合并清单中被天真地处理为:

<intent-filter>
    <data android:host="string" />
    <data android:path="/my_link_uri" />
</intent-filter>

因此说明了导航组件无法正确解析字符串资源。