android – Matching a url pattern in <intent-filter>-ThrowExceptions

Exception or error:

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:

      android:name="android.intent.action.VIEW" />
      android:name="android.intent.category.DEFAULT" />
      android:name="android.intent.category.BROWSABLE" />

      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,


How to solve:

I had the same problem today, my solution was:

   <data android:pathPattern="/remotes/..*/..*"/>

using (..*) as a replacement for (.+)

In the original question’s case I guess that this can work:



Since android OS uses PatternMatcher and observing from source code and documentation it can only work with . * and \\(escape characters) we might need to be a little creative – i.e., use \\ to stop regex evaluation and then resume from then onwards.


which will only match and not

To create different intent filters with varying uri use / at the end of the uri like

Sample solution, use instead of and then use android:pathPattern=".*\\/ android:pathPattern=".*\\/foo/.*\\/ android:pathPattern=".*\\/foo/.*\\/bar/.*\\/


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,

where the two captured groups are equal, just pass http://mystuff/abc123 in the intent, and set the data pattern to http://mystuff/*

then parse that when you receive the intent, and transform it into the real URL by filling in the known constant parts.

Leave a Reply

Your email address will not be published. Required fields are marked *