I’d like one of my activities to pick up a particular url. The pattern is:
The path components “abc123” and “xyz789” can be any sequence of alpha-numerics, length > 1.
Doing this in my manifest:
<activity> <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" android:host="example.com" android:pathPattern="/.*/foo/.*" />
but it seems that any pattern from my domain is getting matched, ie:
both get matched. I guess maybe the .* operator is not working as I expect here? Any help would be great,
I had the same problem today, my solution was:
using (..*) as a replacement for (.+)
In the original question’s case I guess that this can work:
<data android:host="example.com" android:pathPattern="..*/foo/..*" android:scheme="http"/>
Since android OS uses PatternMatcher and observing from source code and documentation it can only work with
\\(escape characters) we might need to be a little creative – i.e., use
\\ to stop regex evaluation and then resume from then onwards.
<data android:host="example.com" android:pathPattern=".*\\/foo/.*" android:scheme="http"/>
which will only match
myexample.com/whatever and not
To create different intent filters with varying uri use
/ at the end of the uri like
Sample solution, use http://www.example.com/abc123/foo/xyz789/ instead of http://www.example.com/abc123/foo/xyz789 and then use
the problem is that .* matches everything, -and nothing-, so “/.*/” matches “//”, which is equivalent to just “/” in a path.
also, you can ensure that the two path segments “abc123” in your example are equal with the expression matcher supported here.
in other words, you want want to alter your paths to something simpler that can be matched. if it’s your component that’s receiving the intent, you can pass a fake URL that is just the variable parts of the real URL. for example, if you want to match,
then parse that when you receive the intent, and transform it into the real URL by filling in the known constant parts.