Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Deeplink pathPrefix Attribute Is Being Ignored

I have a deeplink defined for my Android app in the manifest file:

  <activity android:name="com.example.DeeplinkActivity"
        android:screenOrientation="portrait"
        android:theme="@style/MyBaseTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />

                         <!-- Accepts URIs that begin with "example://shelf” -->
            <!-- Currently handles Ads deeplink structure (iPhone structure) -->
            <data
                android:host="shelf"
                android:pathPrefix=""
                android:scheme="example" />

            <!-- Accepts URIs that begin with "example://com” -->
            <data
                android:host="com"
                android:pathPrefix=""
                android:scheme="example" />

            <!-- Accepts URIs that begin with http://www.example.com/some/sample/page.htm” -->
            <data
                android:host="www.example.com"
                android:pathPrefix="/some/sample/page.htm"
                android:scheme="http" />
        </intent-filter>
    </activity>

I have also some links in my app that look similar but should NOT be treated as deeplinks. They do begin with http://www.example.com but they have a completly different prefix. For example: http://www.example.com/other/not/deep/link.htm .

For some reason the intent filter defined for DeeplinkActivity is being trigerred even though it is defined with the prefix "/some/sample/page.htm".

Does the prefix being ignored? if not why one should use the the pathPrefix attribute when defining the deeplink intent filter?

like image 320
Maxim Rahlis Avatar asked Jun 23 '15 12:06

Maxim Rahlis


People also ask

How do I enable deep link on Android?

Click + in the Deep Links section of the Attributes panel. In the Add Deep Link dialog that appears, enter the info for your deep link. Note the following: URIs without a scheme are assumed as either http or https.

How do I open a deeplink URL?

Select Open deep link URL in a browser option. Click Next. For Android, select Open the deep link in your Android app. Then select your app from the dropdown, in this case the com.

What is deeplink activity?

Deeplinks are a concept that help users navigate between the web and applications. They are basically URLs that navigate users directly to the specific content in applications.


1 Answers

Removing the pathPrefix didn't solve the problem for me, I either ended up with all http deep links working or none of them, regardless of prefix. It seems like the prefixes, hosts and schemes all bleed into eachother, so with your example example://www.example.com/ would probably also trigger a deep link even though none of the individual data elements define it. I ended up figuring out that you can just separate them into different intent-filters and they wont mix.

So in your case you could use:

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

                     <!-- Accepts URIs that begin with "example://shelf” -->
        <!-- Currently handles Ads deeplink structure (iPhone structure) -->
        <data
            android:host="shelf"
            android:pathPrefix=""
            android:scheme="example" />

        <!-- Accepts URIs that begin with "example://com” -->
        <data
            android:host="com"
            android:pathPrefix=""
            android:scheme="example" />

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

        <!-- Accepts URIs that begin with http://www.example.com/some/sample/page.htm” -->
        <data
            android:host="www.example.com"
            android:pathPrefix="/some/sample/page.htm"
            android:scheme="http" />

    </intent-filter>

this will only accept http URIs that begin with http://www.example.com/some/sample/page.htm OR URIs begining with example://com or example://shelf

so in your originial question, http://www.example.com/other/not/deep/link.htm will not trigger a deep link.

like image 148
JStephen Avatar answered Sep 20 '22 13:09

JStephen