Intent filter using path,pathPrefix, or pathPatter

2020-07-02 09:39发布

My test uri string is

http://test.host.com/path/test.html?key1=val1&key2=val2

And I make intent-filter in manifest

A. scheme & host (It works but I do not want)

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <data
        android:scheme="http"
        android:host="test.host.com"
    />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

B. A & path(pathPrefix, pathPattern) (Not worked)

    <data
        android:scheme="http"
        android:host="test.host.com"

        1. android:path="path/test.html" -> not worked (link to chrome broswer)
        2. android:path="path"           -> not worked (link to chrome broswer)
        3. android:pathPrefix="path"     -> not worked (link to chrome broswer)
        4. android:pathPattern="user/invite.*"  -> same (I do not know pattern)

    />

I want to start my app when only (path/test.html),

3条回答
三岁会撩人
2楼-- · 2020-07-02 10:03

If you need start your app only If for link /path/test.html Then Use android:path attribute in data tag only

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="http"
        android:host="test.host.com"
        android:path="/path/test.html" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

As android:path attribute specifies a complete path that is matched against the complete path in an Intent object. But android:pathPrefix attribute specifies a partial path that is matched against only the initial part of the path in the Intent object.

So when use android:pathPrefix attribute not android:path attribute That mean your app may start for /path/test.html, /path/test.html?key1=value1,/path/test.html?key1=value1&key2=value2,etc

More Information about android doc for data tag into intent-filter

查看更多
我只想做你的唯一
3楼-- · 2020-07-02 10:05

You are missing the slash at the beginning. The following should work:

android:path="/path/test.html"

OR

android:pathPrefix="/path/test.html"
查看更多
爷、活的狠高调
4楼-- · 2020-07-02 10:11

The pathPrefix attribute specifies a partial path that is matched against only the initial part of the path in the Intent object.

android:pathPrefix="/path/" will also work.

查看更多
登录 后发表回答