具有多个查询参数的 Android 深度链接

我正在尝试深度链接我的应用程序,并在 AndroidManifest.xml 中实现了以下内容来打开适当的活动。

<activity
android:name=".ui.activities.MyActivity"
android:label="@string/title_activity"
android:screenOrientation="portrait">
<!-- ATTENTION: This intent was auto-generated. Follow instructions at
https://g.co/AppIndexing/AndroidStudio to publish your Android app deep links. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />


<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- ATTENTION: This data URL was auto-generated. We recommend that you use the HTTP scheme.
TODO: Change the host or pathPrefix as necessary. -->
<data
android:host="myHost"
android:scheme="myCustomScheme" />
</intent-filter>
</activity>

我正在测试 adb 的活动

adb shell am start -W -a android.intent.action.VIEW -d "myCustomScheme://myHost?key=category_parent_id&value=92&title=test" com.myApp.android

活动正在打开,但是在意图中传递给活动的 URI 只是

myCustomScheme://myHost?key=category_parent_id

它跳过了“ &”之后的所有内容

我在这里查找了 SO,但没有发现任何有多个查询参数的内容。

41683 次浏览

Just add \ before & sign when testing with adb.

Copy this:

adb shell am start -W -a android.intent.action.VIEW -d "myCustomScheme://myHost?key=category_parent_id\&value=92\&title=test" com.myApp.android

You can wrap the shell command with simple quotes (to avoid modifying the uri content):

adb shell 'am start -d "myCustomScheme://myHost?key=category_parent_id&value=92&title=test"'

Just encode your url parameters and it will work. It might be google's parsing bug.

Before:

adb shell am start -W -a android.intent.action.VIEW -d "myCustomScheme://myHost?key=category_parent_id&value=92&title=test" com.myApp.android

After:

adb shell am start -W -a android.intent.action.VIEW -d "myCustomScheme://myHost?key%3Dcategory_parent_id%26value%3D92%26title%3Dtest" com.myApp.android

For osx / mac users with android studio

Load adb

export PATH="/Users/your_user/Library/Android/sdk/platform-tools":$PATH

Check that the app is recognized

adb shell am start -n com.package/.activities_package_name.MainActivity

Test deeplink

adb shell 'am start -W -a android.intent.action.VIEW -d "myCustomScheme://myHost?key=category_parent_id\&value=92\&title=test" com.myApp.android'

Don't forget the ' '