Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android deep links not following path prefix

The closest I could find was this question here. but it doesnt quite cover the problem im having.

I have deep links in my app setup to use /app as the path prefix. The problem I'm having is that links like http://example.com/upgrade are also trying to open in my app even though it doesn't have /app anywhere in the url. I understand you cant exclude urls specified by the prefix, but isn't the whole point of path prefix to include only those urls?

basically I want links like these to deep link:

http://example.com/app/home
http://example.com/app/specials

but not links like these:

http://exaple.com/
http://example.com/login

and here is what I have in my manifest:

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

Edit 1

also found this link but i dont have any empty prefixes, only ones with just a slash "/"

Edit 2

The url that was triggering it was http://example.com/upgrade.php?app=1&method=1&uid=1, I wasn't sure if app after the ? would also trigger it so I changed the prefix to /application but that also didn't work, its still triggering them.

Edit 3

here are the other deep link data tags in the manifest:

profile activity

<data android:scheme="myapp"
    android:host="profile"
    android:pathPrefix="/"/>

login/signup activity

<data android:scheme="myapp"
     android:host="login"
     android:pathPrefix="/signup"/>

main activity

<data android:scheme="myapp"
     android:host="main"
     android:pathPrefix="/"/>

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

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

Edit 4

This is getting more and more confusing, if I remove the data tag with myapp as the scheme from the activity (or if i remove the pathPrefix from everything with a prefix of "/") it no longer triggers the deep links from the web urls, even if they have /app in them.

like image 580
JStephen Avatar asked Dec 14 '15 21:12

JStephen


People also ask

How do I enable deep link on Android?

Android Studio makes it very easy to test deep links. Click Run > Edit Configurations to edit the configuration of the project. Open the General tab at the top and enter the URI in the Deep Link field in the Launch Options section.

How does deeplink work on Android?

A Deep Link is a URL link that is generated, when anyone clicks on that link our app will be open with a specific activity or a screen. Using this URL we can send a message to our app with parameters. In WhatsApp, we can generate a deep link to send a message to a phone number with some message in it.

How do I configure deeplink?

To use the tool, log in to your Adjust dashboard and open the Menu, where you'll see the 'Deeplink Generator' as an option. Click to open, and you'll find a page to input the information required to create your deep link. Then simply copy and paste into whichever campaign you've set up.

How do I integrate a deep link app on Android?

First, you specify the BROWSABLE category so your deep link can work in a browser. Without it, clicking the deep link on a browser won't resolve to your app. Second, the DEFAULT category lets your app handle implicit intents. If it's missing, the intent must specify the app component name for the activity to start.


2 Answers

I figured it out, It seems like the data tags sort of bleed into one another, so the prefix of "/" on the data with scheme "example" was also applying to all of the schemes in the other data tags. I just had to use separate Intent filters for my custom scheme deep links and the url deep links like so:

<activity android:name=".MainActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />

        <!-- must start with http://test.example.com/app -->
        <!-- http://test.example.com/ won't work since prefix / is in a different intent-filter -->
        <data android:scheme="http"
            android:host="test.example.com"
            android:pathPrefix="/app"/>

        <!-- must start with http://live.example.com/app -->
        <data android:scheme="http"
            android:host="live.example.com"
            android:pathPrefix="/app"/>

    </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" />

        <!-- must start with example://main/ -->
        <!-- http://test.example.com/ won't work since http is in a different intent-filter -->
        <data android:scheme="example"
            android:host="main"
            android:pathPrefix="/"/>

    </intent-filter>
</activity>
like image 93
JStephen Avatar answered Oct 14 '22 21:10

JStephen


As explained here, your attributes get merged:

Although it's possible to include multiple <data> elements in the same filter, it's important that you create separate filters when your intention is to declare unique URLs (such as a specific combination of scheme and host), because multiple <data> elements in the same intent filter are actually merged together to account for all variations of their combined attributes.

Putting them into separate instances of <intent-filter> therefore fixes your problem.

like image 44
saraedum Avatar answered Oct 14 '22 20:10

saraedum