【发布时间】:2021-10-05 12:54:03
【问题描述】:
我正在使用 Android Navigation UI 在我的应用中进行导航。我需要在我的第二个片段中打开一个 Web URL(动态链接)。
这是我在导航图中的代码
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mobile_navigation"
app:startDestination="@+id/nav_home">
<fragment
android:id="@+id/nav_home"
android:name="com.myproject.main.HomeFragment"
android:label="Home"
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_nav_home_to_secondFragment"
app:destination="@id/secondFragment" />
</fragment>
<fragment
android:id="@+id/nav_library"
android:name="com.myproject.main.SecondFragment"
android:label="@string/menu_library"
tools:layout="@layout/fragment_library">
<deepLink
android:id="@+id/deepLink"
app:uri="https://myproject.page.link/*" />
</fragment>
</navigation>
并将此导航图添加到清单中的主要活动中
<activity
android:name=".main.MainActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"
>
<nav-graph android:value="@navigation/mobile_navigation" />
</activity>
当用户单击 https://myproject.page.link/i5sA 之类的 URL 时,我想打开我的第二个片段,但是当我单击此链接时,我的应用程序甚至没有被提示在此应用程序中打开。仅提示浏览器。当我点击使用 chrome 浏览器打开时,它只会使用默认的起始目的地打开我的应用程序。
我需要的是,当用户按下该网页 URL 时,我需要使用 SecondFragment 打开我的应用 MainActivity 并获取该 URL 数据,而不是打开默认的主页片段。
我看过developer page 和很多文章和教程,但我不知道我在这里缺少什么,任何人都可以告诉我...
【问题讨论】:
标签: android deep-linking android-navigation android-navigation-graph