Android深层链接未遵循路径前缀 [英] Android deep links not following path prefix
问题描述
我能找到的最接近的问题是此处.但这并不能完全解决我所遇到的问题.
The closest I could find was this question here. but it doesnt quite cover the problem im having.
我的应用程序设置中有深层链接,可以将/app用作路径前缀.我遇到的问题是,即使http://example.com/upgrade
之类的链接也试图在我的应用程序中打开,即使它在URL中的任何位置都没有/app.我知道您不能排除由前缀指定的网址,但不是整个路径前缀都只包含那些网址吗?
I have deep links in my app setup to use /app as the path prefix. The problem I'm having is that links like http://example.com/upgrade
are also trying to open in my app even though it doesn't have /app anywhere in the url. I understand you cant exclude urls specified by the prefix, but isn't the whole point of path prefix to include only those urls?
基本上,我希望像这样的链接成为深层链接:
basically I want links like these to deep link:
http://example.com/app/home
http://example.com/app/specials
但不是这样的链接:
http://exaple.com/
http://example.com/login
这就是清单中的内容:
<data android:scheme="http"
android:host="example.com"
android:pathPrefix="/app"/>
编辑1
还找到了此链接,但我没有任何空前缀,只有那些带有斜线"/"的
also found this link but i dont have any empty prefixes, only ones with just a slash "/"
编辑2
触发它的网址是http://example.com/upgrade.php?app=1&method=1&uid=1
,我不确定应用程序是否在?之后.也会触发它,所以我将前缀更改为/application,但这也没有用,仍然会触发它们.
The url that was triggering it was http://example.com/upgrade.php?app=1&method=1&uid=1
, I wasn't sure if app after the ? would also trigger it so I changed the prefix to /application but that also didn't work, its still triggering them.
编辑3
以下是清单中的其他深层链接数据标签:
here are the other deep link data tags in the manifest:
个人资料活动
<data android:scheme="myapp"
android:host="profile"
android:pathPrefix="/"/>
登录/注册活动
<data android:scheme="myapp"
android:host="login"
android:pathPrefix="/signup"/>
主要活动
<data android:scheme="myapp"
android:host="main"
android:pathPrefix="/"/>
<data android:scheme="http"
android:host="test.example.com"
android:pathPrefix="/app"/>
<data android:scheme="http"
android:host="live.example.com"
android:pathPrefix="/app"/>
修改4
这变得越来越混乱,如果我从活动中删除使用myapp作为方案的数据标签(或者如果我从前缀为"/"的所有内容中删除pathPrefix),则不再触发来自Web网址,即使其中包含/app.
This is getting more and more confusing, if I remove the data tag with myapp as the scheme from the activity (or if i remove the pathPrefix from everything with a prefix of "/") it no longer triggers the deep links from the web urls, even if they have /app in them.
推荐答案
我发现了这一点,似乎数据标签有点相互渗入,因此数据"/"的前缀带有方案"example"也适用于其他数据标签中的所有方案.我只需要对我的自定义方案深层链接和url深层链接使用单独的Intent过滤器,如下所示:
I figured it out, It seems like the data tags sort of bleed into one another, so the prefix of "/" on the data with scheme "example" was also applying to all of the schemes in the other data tags. I just had to use separate Intent filters for my custom scheme deep links and the url deep links like so:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- must start with http://test.example.com/app -->
<!-- http://test.example.com/ won't work since prefix / is in a different intent-filter -->
<data android:scheme="http"
android:host="test.example.com"
android:pathPrefix="/app"/>
<!-- must start with http://test.example.com/app -->
<data android:scheme="http"
android:host="live.example.com"
android:pathPrefix="/app"/>
</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" />
<!-- must start with example://main/ -->
<!-- http://test.example.com/ won't work since http is in a different intent-filter -->
<data android:scheme="example"
android:host="main"
android:pathPrefix="/"/>
</intent-filter>
</activity>
这篇关于Android深层链接未遵循路径前缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!