Android deeplinking: match url only when no path
Asked Answered
P

5

10

Given the following URLS:

1. www.example.com

2. www.example.com/a

Via deeplinking, I want my app to only react on 1 and not 2.

            <data
                android:host="*.example.com"
                android:pathPrefix="/"
                android:scheme="http"/>

This will, of course, catch all www.example.com/... urls, how can I match only www.example.com without any path and not match www.example.com/a?

Phonogram answered 1/9, 2016 at 8:34 Comment(3)
Did you try <data android:host="example.com" android:path="" android:scheme="http"/> ?Tymes
That didnt work, but <data android:host="example.com" android:path="/" android:scheme="http"/> did, so the trick was to use path instead of pathPrefix od pathPattern. If you post this as an answer, i'll accept it ;) Thanks!Phonogram
You did find the correct answer. You can write it and also accept it ;)Tymes
C
6

Here's what worked for me, set path empty and include a tools:ignore to avoid lint errors.

<data
     android:host="*.example.com"
     android:path=""
     android:scheme="http"
     tools:ignore="AppLinkUrlError"
            />
Chemo answered 22/8, 2018 at 18:2 Comment(0)
P
2

Using 'path' instead of 'pathPrefix' or 'pathPattern' worked, so:

        <data
            android:host="*.example.com"
            android:path="/"
            android:scheme="http"/>

matches www.example.com as well as www.example.com/, but not www.example.com/a, so exactly what I wanted.

Phonogram answered 1/9, 2016 at 21:51 Comment(2)
Does this still work? For me it only works for http://example.com/, not http://www.example.com unfortunatelyKnee
Nope. Only www.example.com/ worksWaybill
A
1

Old question but what worked for me was adding two data inputs

            <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.com"
                    android:path=""
                    tools:ignore="AppLinkUrlError"
                    android:scheme="https" />

                <data
                    android:host="*.example.com"
                    android:path="/"
                    android:scheme="https" />
            </intent-filter>

Adding just one of them would handle either www.example.com or www.example.com/. You can also put them in different intent filters.

Adiaphorous answered 27/1, 2021 at 14:18 Comment(0)
S
0

I had the same problem and find a solution for matching nude domain like www.example.com

<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="www.example.com"/>
</intent-filter>

The key is to add a intent-filter without any path-like attribute.

Sisak answered 13/2, 2018 at 14:48 Comment(1)
wouldn't that also react to www.example.com/a?Pellikka
H
0

In case you want to match both http://example.com/ and http://example.com, I can confirm @Anigif comment: using a single data element containing path="/" doesn't work anymore, as it only matches http://example.com/, but does not match http://example.com.

However, adding two data elements to the same intent works:

<data android:scheme="http" android:host="*.example.com" android:path="/"/>
<data android:scheme="http" android:host="*.example.com" android:path=""/>

This matches http://example.com/ and http://example.com but does not match http://example.com/a.

Hideous answered 24/2, 2021 at 12:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.