问题
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).
回答1:
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.
来源:https://stackoverflow.com/questions/49713357/deep-link-does-not-work-on-android