'Deeplinks with Query Params with nav component in android
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}&type={type}" />
</fragment>
If I remove the deeplinkList, deeplinkDetails will work fine. How can I fix this issue?
Solution 1:[1]
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&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)
Solution 2:[2]
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>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | hushed_voice |
| Solution 2 | Marsad |
