【发布时间】:2015-12-24 09:53:50
【问题描述】:
我的清单中定义了以下内容:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.package">
...
<activity
android:name="app.myActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="www.example.com"
android:pathPrefix="/gizmos"
android:scheme="http" />
<!-- note that the leading "/" is required for pathPrefix-->
<!-- Accepts URIs that begin with "example://gizmos”-->
<data
android:host="gizmos"
android:scheme="example" />
</intent-filter>
</activity>
...
我已经这样定义了我的 onCreate():
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Uri data = intent.getData();
if (data != null) {
Log.d("URI",data.toString());
}
}
这是根据 Android 文档:Android Deep Linking
所以问题是:
如何测试 URI 深层链接?根据文档,我运行类似
adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.app.package
但这会产生:
错误:Activity 未启动,无法解析 Intent { act=android.intent.action.VIEW dat=example://gizmos flg=0x10000000 pkg=com.app.package }
我还尝试了带有活动名称和引用的外壳,启动器活动并将包留空。我唯一能去上班的是:
adb shell am start -W -a android.intent.action.VIEW -d "http://www.example.com/gizmos"
但即使我做到了,这也不是说它可以在其他应用程序中工作。自定义 URI(例如 example://gizmos)在 Gmail 和 WhatsApp 等其他应用中不可点击 - 因此在 Android 生态系统中进行测试也存在问题。
at this stack overflow question 的答案是不可接受的,因为它不回答问题,而只是鼓励使用 http:// 版本,我希望 example:// 方案能够工作。
【问题讨论】:
-
请不要试图将多个问题塞进一个帖子中。即使你认为它们是相关的。
标签: android adb deep-linking