I'd like one of my activities to pick up a particular url. The pattern is:
http://www.example.com/abc123/foo/xyz789
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:
myexample.com
myexample.com/whatever
both get matched. I guess maybe the .* operator is not working as I expect here? Any help would be great,
Thanks
http://developer.android.com/guide/topics/manifest/data-element.html
An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.
However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another. An <intent-filter> element in the manifest file lists actions as <action> subelements. For example: <intent-filter . . . >
Categories are used for implicit Intents. So, If your Activity can be started by an implicit Intent when no other specific category is assigned to activity, activity's Intent filter should include this category. (even if you have other categories in the Intent filter).
An intent filter declares the capabilities of its parent component — what an activity or service can do and what types of broadcasts a receiver can handle. It opens the component to receiving intents of the advertised type, while filtering out those that are not meaningful for the component.
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:
<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 .
*
and \\
(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 myexample.com
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
example.com/abc123/ android:pathPattern=".*\\/
example.com/abc123/foo/xyz789/ android:pathPattern=".*\\/foo/.*\\/
example.com/abc123/foo/xyz789/bar/uvx456/ 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,
http://www.example.com/.+/foo/.+
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With