Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Arch Component: Passing placeholder param for deeplink

I am trying to implement a deeplink functionality using the new Navigation Component API v1.0.0-alpha05 but running into an issue.

Using Android Studio 3.3 Canary 7

Portion of my 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 contains:

    <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>

I am testing my deeplink with adb shell am start -a android.intent.action.VIEW -d "notesapp://notes/2" com.myapp.notes

The noteId is not present in either NoteDetailFragmentArgs.fromBundle(arguments).noteId or arguments?.getInt("noteId", 0) (a default value of 0 is returned in both cases)

Printing out the Bundle shows that it is there:

[{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}]

The same issue is observed if the deeplink uri is http://www.mynotes.com/notes/2

How do I access the noteId when deeplinking? Thanks!

like image 503
liminal Avatar asked Sep 05 '18 01:09

liminal


2 Answers

As per this issue, arguments parsed from deep links are only added to the arguments Bundle as Strings.

Therefore you should retrieve the noteId via arguments?.getString("noteId")?.toInt() until that issue is fixed.

like image 54
ianhanniballake Avatar answered Oct 31 '22 22:10

ianhanniballake


The issue was fixed in android.arch.navigation 1.0.0-alpha09.

Bug Fixes

Arguments are now properly parsed from deep links as the correct argType instead of always as strings b/110273284

Arch Components Release notes: https://developer.android.com/jetpack/docs/release-notes

like image 30
liminal Avatar answered Oct 31 '22 22:10

liminal