[ Android ICS ]
PatternMatcher is used for pathPattern at IntentFilter
But, PatternMatcher's algorithm is quite strange to me.
Here is algorithm of Android PatternMatcher.
If there is 'next character' of '.*' pattern in the middle of string, PatternMatcher stops loop at that point.
(See PatternMatcher.java of Android framework.)
Ex.
string : "this is a my attachment"
pattern : ".*att.*".
Android PatternMatcher enter loop to match '.*' pattern until meet the next character of pattern
(at this example, 'a')
So, '.*' matching loop stops at index 8 - 'a' between 'is' and 'my'.
Therefore result of this match returns 'false'.
Quite strange, isn't it.
To workaround this - actually reduce possibility - developer should use annoying stupid pathPattern.
Ex.
Goal : Matching uri path which includes 'message'.
<intent-filter>
...
<data android:pathPattern=".*message.*" />
<data android:pathPattern=".*m.*message.*" />
<data android:pathPattern=".*m.*m.*message.*" />
<data android:pathPattern=".*m.*m.*m.*message.*" />
<data android:pathPattern=".*m.*m.*m.*m.*message.*" />
...
</intent-filter>
This is especially issued when matching with custom file extention.
Ex.
Goal : Matching file which extention is 'myextention'.
Below filter doesn't work as expected because of issue described above.
(Ex. "sample.test.myextention" doesn't match by PatternMatcher.)
<intent-filter>
...
<data android:pathPattern=".*\\.myextention" />
...
</intent-filter>
So, like above, stupid-dirty filter should be used as follows.
<intent-filter>
...
<data android:pathPattern=".*\\.myextention" />
<data android:pathPattern=".*\\..*\\.myextention"/>
<data android:pathPattern=".*\\..*\\..*\\.myextention"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.myextention"/>
...
</intent-filter>
Done. :-)