我在我的清单文件中定义了以下内容:
<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深度链接。
问题是: 如何测试URI深度链接?根据文档,我可以运行以下命令:
但是会出现以下错误:adb shell am start -W -a android.intent.action.VIEW -d "example://gizmos" com.app.package
我还尝试过使用活动名称和引用、启动器活动以及将包留空的shell。唯一一个可以正常工作的是:Error: Activity not started, unable to resolve Intent { act=android.intent.action.VIEW dat=example://gizmos flg=0x10000000 pkg=com.app.package }
即使我成功了,也不能保证它在其他应用程序中能够工作。自定义URI(例如example://gizmos)在其他应用程序中,如Gmail和WhatsApp中无法点击 - 因此,在Android生态系统中进行测试也存在问题。 此堆栈溢出问题的答案不可接受,因为它没有回答问题,而只是鼓励使用http://版本,我希望example://方案能够正常工作。adb shell am start -W -a android.intent.action.VIEW -d "http://www.example.com/gizmos"