As per the documentation, run the following from Terminal.
adb shell am start -a android.intent.action.VIEW -d "https://example.com/?key1=value1&key2=value2"
Note that you have to escape &
to %26
to pass more than one query parameter.
- Open Android Studio.
- Go to Menu bar >
Run
>Edit Configurations
>General
tab >Launch
>URL
. - Put the following in
URL
.
https://example.com/?key1=value1&key2=value2
- Run the app.
The following steps are already done in this sample app.
- Create a navigation graph XML like
res/navigation/nav_graph.xml
.
<navigation xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/FirstFragment">
<fragment
android:id="@+id/FirstFragment"
android:name="com.github.tatsuyafujisaki.deeplinkarbitraryquerysample.FirstFragment" >
<!-- The domain must ends with a trailing slash (i.e. example.com -> example.com/) to get a query string by KEY_DEEP_LINK_INTENT. -->
<deepLink app:uri="example.com/" />
</fragment>
</navigation>
- Reference the navigation graph XML in
AndroidManifest.xml
.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
<application ...>
<activity ...>
<nav-graph android:value="@navigation/nav_graph" />
</activity>
</application>
</manifest>
- Add the following in Fragment's
onCreateView()
.
class FirstFragment : Fragment() {
override fun onCreateView(...): View? {
// ...
val queryString = arguments
?.getParcelable<Intent>(NavController.KEY_DEEP_LINK_INTENT)
?.data
?.encodedQuery
// ...
}
}