android - 导航拱组件 : Passing placeholder param for deeplink

标签 android android-architecture-components android-architecture-navigation

我正在尝试使用新的导航组件 API v1.0.0-alpha05 实现深层链接功能,但遇到了问题。

使用 Android Studio 3.3 金丝雀 7

我的 navigation_graph.xml 的一部分

<fragment
    android:id="@+id/noteDetailFragment"
    android:name="com.myapp.notes.notedetail.NoteDetailFragment"
    android:label="@string/label_note_detail"
    tools:layout="@layout/note_detail_fragment">

    <argument
        android:name="noteId"
        android:defaultValue="0"
        app:argType="integer" />

    <action
        android:id="@+id/action_noteDetail_to_editNote"
        app:destination="@id/editNoteFragment" />

    <deepLink
        android:id="@+id/noteDetailDeepLink"
        app:uri="notesapp://notes/{noteId}" />
</fragment>

AndroidManifest.xml 包含:

    <activity android:name=".presentation.MainActivity">
        <nav-graph android:value="@navigation/navigation_graph" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

我正在使用 adb shell am start -a android.intent.action.VIEW -d "notesapp://notes/2"com.myapp.notes

测试我的深层链接

noteId 不存在于 NoteDetailFragmentArgs.fromBundle(arguments).noteIdarguments?.getInt("noteId", 0)(在这两种情况下都返回默认值 0)

打印出 Bundle 表明它在那里:

[{android-support-nav:controller:deepLinkIntent=Intent { act=android.intent.action.VIEW dat=notesapp://notes/2 flg=0x1000c000 pkg=com.mynotes.notes cmp= com.mynotes.notes.presentation.MainActivity }, noteId=2}]

如果深层链接 uri 是 http://www.mynotes.com/notes/2

,也会出现同样的问题

深度链接时如何访问 noteId?谢谢!

最佳答案

根据 this issue ,从深层链接解析的参数仅作为字符串添加到 arguments Bundle。

因此,您应该通过 arguments?.getString("noteId")?.toInt() 检索 noteId,直到该问题得到解决。

关于android - 导航拱组件 : Passing placeholder param for deeplink,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52175818/

相关文章:

android - 即使在使用导航 2.2.1 后仍然有错误 no current navigation node

android - 如何将动态功能模块与 BottomNavigationView 一起使用?

android - 从 Android 内容 URI 获取 FileInputStream(或如何在 InputStream 上查找)

android - 为什么 FusedLoactionProvider.getLocationAvailability() 返回 null(虽然它不应该)?

android - 什么是 "context menu"和方法 registerForContextMenu()

android - 我们可以将 android.app.Service 作为生命周期感知组件吗

android - Livedata 观察者的多个实例

安卓架构组件 : How is LiveData in the repository observed by a ViewModel

android - Android 上的 GridView 滚动问题

android - 在导航组件中包含来自 Backstack 的 fragment