prago
prago

Reputation: 5423

Regex in intent-filter of Android Manifest

I am trying to include a regex in order to implement deeplinking to my activity. We have to activities that share a similar schema which is as follows:

Activity A - http://www.google.com/a/process?abc=xyz Activity B - http://www.google.com/a//?pqr=efg.

Now I declared the deeplink in the manifest as follows :

<activity 
             android:name="com.xyz.samples.ActiivtyB" >
             <intent-filter android:label="SimpleB">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:host="www.google.com"
                    android:pathPrefix="/a/"
                    android:scheme="http" />
            </intent-filter>
        </activity>

The above declaration for Activity B resolves both urls (mentioned above) since they share the same path till '/a/'. However this is not the problem with Activity A, since its manifest is declared as below :

<activity 
                 android:name="com.xyz.samples.ActiivtyA" >
                 <intent-filter android:label="SimpleA">
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <data
                        android:host="www.google.com"
                        android:pathPrefix="/a/process"
                        android:scheme="http" />
                </intent-filter>
            </activity>

Hence I came thought of using "regex" which identifies urls of type /a/, I verified the regex here and it is working. Even I wrote a simple Java program to verify this and it is working fine. The regex is /a/)(?!\bsuccess\b).*

When I tried to create the deeplink with the above regex, app is not able to resolve the URL of type http://www.google.com/a//?pqr=efg. The manifest is updated as follows :

<activity 
                 android:name="com.xyz.samples.ActiivtyB" >
                 <intent-filter android:label="SimpleB">
                    <action android:name="android.intent.action.VIEW" />
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <data
                        android:host="www.google.com"
                        android:pathPattern="(/a/)(?!\\bsuccess\\b).\\*"
                        android:scheme="http" />
                </intent-filter>
            </activity>

Any help or insights on how to declare regex in manifest will be really helpful. I gone thru the Android documentation here and updated the regex accordingly.

Upvotes: 3

Views: 5083

Answers (1)

Emily
Emily

Reputation: 541

You mis-escaped your pattern - .\\* matches the literal string .*. But also:

pathPattern isn't a real regex, but a weird subset of regex. I don't think there's a way to exclude /a/success with those options.

Upvotes: 2

Related Questions