Search code examples
androidregexandroid-manifestdeeplink

Deep linking - PathPattern regex limitations


So my objective is to deep link any URL that has this format MyWebsite/en/flyers/{StoreName}-flyer-{StoreId}

It's working fine for this url https://www.salewhale.ca/en/flyers/walmart-flyer-2864 when the StoreName doesn't have minus symbol. However in this case https://www.salewhale.ca/en/flyers/canadian-tire-flyer-25659 the deep linking won't work, the OS will just open the browser rather picking StoreActivity for any link that has - minus symbol in its StoreName.

Here's my Manifest below you can quickly try.

<activity
        android:name=".ui.activity.StoreActivity"
        ...
        >
        <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:host="www.salewhale.ca"
                android:pathPattern="/fr/circulaires/.*-circulaire-.*"
                android:scheme="https"/>
            <data
                android:host="salewhale.ca"
                android:pathPattern="/en/flyers/.*-flyer-.*"
                android:scheme="http"
                />
        </intent-filter>
    </activity>

PS: I understand that Android pathPattern is not real regex.


Solution

  • I am very late in answering but...

    You must try to parse the path in your activity rather than resolving it using regex because you have a fixed path pattern i.e MyWebsite/en/flyers/{StoreName}-flyer-{StoreId}. So, you can extract StoreName and StoreId using Java instead of relying on Regex when you already know that pathPattern is not real regex.