问题描述
清单中定义了以下内容:
I have the following defined in my manifest:
<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():
And I have defined my onCreate() as such:
@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文档一致:
This is in accordance with the Android documentation: Android Deep Linking
所以问题是:
如何测试URI深度链接?他在文档中运行了类似的命令
但这会产生:
我也尝试了使用活动名称和引用(启动程序活动)的外壳,包装空白。我唯一可以工作的是:
I have also tried the shell with the name and reference of the activity, the launcher activity and left the package blank. The only one I can get to work is:
但是即使我明白了这一点,也并不是说它可以在其他应用程序中使用。自定义URI(例如example:// gizmos)在Gmail和WhatsApp等其他应用中不可点击-因此在Android生态系统中进行测试也是有问题的。
But even if I got this going that isn't to say it's going to work within other apps. CUSTOM URI's (e.g. example://gizmos) are not clickable in other apps like Gmail and WhatsApp - so testing within the Android ecosystem is also problematic.
答案此堆栈溢出问题不能接受,因为它不能回答问题,而只是鼓励使用http://版本,我希望example://方案能够正常工作。
The answer at this stack overflow question is not acceptable since it does not answer the question but rather just encourages the use of the http:// version, I want the example:// scheme to work.
推荐答案
ADB正在发送意图,只是当您想要多种链接类型时,您的应用必须具有单独的意图过滤器:
The ADB is sending the intent, it's just that your app must have separate intent-filters when you want multiple link types:
<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" />
<!-- Accepts URIs that begin with "example://gizmos"-->
<data
android:host="gizmos"
android:scheme="example" />
</intent-filter>
<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-->
</intent-filter>
</activity>
然后,以下ADB命令都可以工作:
Then the following ADB commands both work:
但是我遇到了在自定义URI上附加更多元素的问题(例如example:// gizmos?data1 ='hello'& data2 ='world'-'&'被切断)
However I have encountered problems with more elements appended on to the custom URI (e.g. example://gizmos?data1='hello'&data2='world' - the '&' gets cut off)
很显然,这不能解决这些链接在WhatsApp和Gmail等其他应用中无法单击,而在其他平台上却可以单击。
And obviously this does not fix the fact that these links are not clickable in other apps, like WhatsApp and Gmail... and yet they are clickable on other platforms.
这篇关于具有自定义URI的Android深层链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!