Search code examples
androiddeep-linkingintentfilter

Intent filter for dynamic links is not working as expected


I have following intent filter set up for detecting links to open in our app.

            <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="share.example.tv"
                    android:pathPrefix="/"
                    android:scheme="https" />
                <data
                    android:host="example.tv"
                    android:pathPrefix="/u"
                    android:scheme="https" />
            </intent-filter>

I want my app to open below 2 links

  1. https://share.example.tv/tv34gh
  2. https://example.tv/u/some-user-name

But my app is showing up for these links as well

https://example.tv/anything/literally-anything


Solution

  • If I separate both of the links in different intent-filters for same activity like below

                <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="share.example.tv"
                        android:pathPrefix="/"
                        android:scheme="https" />
                </intent-filter>
    
                <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="example.tv"
                        android:pathPrefix="/u"
                        android:scheme="https" />
                </intent-filter>
    
    

    This works but I don't know why.