2

I have implemented deep linking for my application. And I am handling my deep links by

navController.handleDeepLink(intent)

It's working fine in normal cases.

The issue is when I have deep links like this:

https://example.com/list

It should take me to a listing page

https://example.com/list?id=SOMEID&type=SOMETYPE

This should redirect the user to the details page of the item.

But this is not happening. It always takes me to the listing screen. How can I fix this?

This is how I defined the deeplink in the nav file:

 <deepLink
     android:id="@+id/deeplinkList"
     android:autoVerify="true"
     app:uri="https://example.com/list" />

and details like this:

<fragment>
    <argument
        android:name="id"
        app:argType="string" />
    <argument
        android:name="type"
        app:argType="string" />
    <deepLink
        android:id="@+id/deeplinkDetails"
        android:autoVerify="true"
        app:uri="https://example.com/list?id={id}&amp;type={type}" />
</fragment>

If I remove the deeplinkList, deeplinkDetails will work fine. How can I fix this issue?

Marsad
  • 859
  • 1
  • 14
  • 35
hushed_voice
  • 3,161
  • 3
  • 34
  • 66

2 Answers2

0

What is your Fragment's Activity class?

add this line to the class definition in the manifest file.

 <nav-graph android:value="@navigation/navigation" />

look at the below code for more help:

<activity

    android:name=".ui.main.MainActivity"
    android:alwaysRetainTaskState="true"
    android:configChanges="orientation|screenSize|keyboardHidden"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustPan">
    
    <nav-graph android:value="@navigation/navigation"/>
    
</activity>

Marsad
  • 859
  • 1
  • 14
  • 35
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 28 '22 at 10:31
  • I dont think you understand the question. My deeplinks are working. The issues is with query params in deeplinks – hushed_voice Mar 01 '22 at 11:18
0

Well since I couldn't get a satisfactory answer I found a sort of a hack

I changed the deeplink in navigation file to be without query params. like this:

https://example.com/list/{SOMEID}/{SOMETYPE}

instead of this:

https://example.com/list?id=SOMEID&amp;type=SOMETYPE

and I am manipulating the deeplink the way I want before calling the

navController.handleDeepLink(intent)

like this

val uri = intent.data
intent.data = Uri.parse(
                    "https://example.com/list/${uri?.getQueryParameter("id")}/${uri?.getQueryParameter("id")}")
navController.handleDeepLink(intent)
hushed_voice
  • 3,161
  • 3
  • 34
  • 66