Android Deeplink pathPrefix Attribute Is Being Ignored

后端 未结 2 1024
被撕碎了的回忆
被撕碎了的回忆 2021-01-12 12:41

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

  

        
相关标签:
2条回答
  • 2021-01-12 13:02

    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.

    0 讨论(0)
  • 2021-01-12 13:23

    Apparently, an empty android:pathPrefix attribute in some other data tags will cause specific data tag (the last data tag in above question) to ignore its own pathPrefix even though it is well defined!

    So this manifest declaration fixes the last data tag to behave normally:

      <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:scheme="example" />
    
            <!-- Accepts URIs that begin with "example://com” -->
            <data
                android:host="com"
                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>
    
    0 讨论(0)
提交回复
热议问题