I have read quite a few other SOs on this - in particular the highly-voted answer to this question: Android intent filter for a particular file extension?
My scenario is somewhat simpler - I simply want to match a particular filename on our website - e.g. http://our_domain/filename.extn
- but taking into account some minor variance in case (I call this out further down).
I've written my intent-filter as follows:
<data
android:scheme="http"
android:host="our_domain"
android:pathPattern="/filename\\.extn" />
Double-escaping the \
so that it will be read out of the XML as \.
, thus escaping the period so that the pattern matcher sees a literal .
instead of the 'any' character.
For my tests I've written a small app that takes a string from a text box, creates an ACTION_VIEW
intent with the given URI, and starts it - then checking whether the browser launches or whether I see a chooser with my app listed.
The app is correctly identified for the exact path - e.g. http://our_domain/filename.extn
, but it is also being identified if I replace the .
with any other character that's valid in a URI path - e.g, all of the following also trigger a match:
http://our_domain/filename'extn
http://our_domain/filename~extn
http://our_domain/filenameaextn
The last of which is the most worrying!
How can I set the path pattern to ensure that only a literal period matches?
Please note, I am aware that simply using path
instead of pathPattern
might work - however, the pattern also incorporates some minor case-insensitivity - e.g. F*f*ileN*n*ame
- I have removed this stuff for the question as it makes no difference to the behaviour of this period-matching.
Is it possible that matching only literal .
characters is actually not supported by the intent-filter system (not by design but by bug), and that they'll always be treated as 'any'?