8

I'm following Create Deep Links to App Content in Android developer documentation to create a Deep Link to an Activity in an Android app.

New app project, I've specified the activity exactly like in that tutorial:

<activity
android:name="com.example.android.GizmosActivity"
android:label="@string/title_gizmos" >
<intent-filter android:label="@string/filter_view_http_gizmos">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Accepts URIs that begin with "http://www.example.com/gizmos” -->
    <data android:scheme="http"
          android:host="www.example.com"
          android:pathPrefix="/gizmos" />
    <!-- note that the leading "/" is required for pathPrefix-->
</intent-filter>
<intent-filter android:label="@string/filter_view_example_gizmos">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Accepts URIs that begin with "example://gizmos” -->
    <data android:scheme="example"
          android:host="gizmos" />
</intent-filter>
</activity>

When I test with adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.example.android it works. The OS on the phone launches the app.

But when I test by navigating chrome to example://gizmos the app does not launch and chrome just does a google search for that URI. Why isn't it working?

(I'm using the Android Emulator for Nexus 5X API 26).

mipnw
  • 2,135
  • 2
  • 20
  • 46
  • Can u remove that multiple tags of intentfilter to single and can put multiple data tags inside it – Amjad Khan Apr 08 '18 at 04:35
  • 1
    I could but according to Benjamin's answer it's unlikely to help if Chrome does not follow deep links provided in the address bar. I need to test this by hosting a webpage. Also the deep link documentation says merging multiple `intentfilter` into a single one with multiple `data` has a different meaning, c.f. "Although it's possible to include multiple elements in the same filter, it's important that you create separate filters when your intention is to declare unique URLs". – mipnw Apr 08 '18 at 05:09

1 Answers1

9

This caused by Chrome not following deep links if you manually type it into the address bar. See this answer for more information.

The easiest way to test deep linking is to enter the link into the Android Messages app. After you send the message you can click on the link.

You can also host a page somewhere with your deep link.

Jade
  • 3,156
  • 1
  • 34
  • 44
  • 2
    I've tried the messages app, when I send myself a URI with http scheme, the link is clickable and it works! For some reason an example scheme inside a text message doesn't show up a clickable link so I couldn't test that `example://gizmos` but I have no reason to believe it wouldn't work when `http://www.example.com/gizmos` works fine. Thanks.! – mipnw Apr 08 '18 at 05:25