2016-06-16 23 views
3

这看起来很简单,但我不知道如何去做。意向过滤器只匹配域(没有路径)

我需要我的应用程序在用户点击域名网址时打开。 我需要匹配没有路径的域(android:host)的URL。 example.com或example.com/

我得到它的工作example.com/(带斜杠),但没有斜杠我永远不能捕捉到的网址:example.com

我试着用pathPattern/*,它不起作用。

下面是我的Android清单:

<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:scheme="http" /> 
    <data android:scheme="https" /> 

    <data android:host="example.com" /> 
    <data android:host="www.example.com" /> 

    <data android:pathPattern="/*" /> 
    <data android:path="/" /> 
</intent-filter> 

简单的说,我希望有或没有结束的斜杠 “/” 相匹配的URL。 http://example.com http://example.com/

回答

-1

你不需要多个数据标签,你只需要一个这种情况。每个数据标签可以有一个方案,主机,路径,路径模式等等。如果没有方案,其余部分将被忽略。如果没有主机(但方案),路径属性将被忽略。做你想做什么正确的方法是

<data android:scheme="http" android:host="example.com" />

,这是你应该需要。 Docs

+0

这不起作用。没有路径参数时,只匹配'http:// example.com /',而不是'http:// example.com'(通过'adb shell start'测试) –