简体   繁体   中英

Android deep links - Multiple re-direct with same url

In my application i am using deep links to navigate to Particular activity. I want to navigate to different activities with same basePrefix with different context path at end.

<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="https"
                android:host="www.mycompany.com"
                android:pathPrefix="/profile/friendslist"/>
        </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:scheme="https"
                android:host="www.mycompany.com"
                android:pathPrefix="/profile/friendslist/details"/>
        </intent-filter>

./adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://www.mycompany.com//profile/friendslist" com.mycompany.sample: It launches FriendsListFragment

./adb shell am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://www.mycompany.com//profile/friendslist/details" com.mycompany.sample: It also launches FriendsListFragment instead of FriendsListDetailsFragment

What i want to do is

/profile/friendslist/: should open FriendsList

/profile/friendslist/details?id=1234 should navigate to FriendDetails

Anyone suggest how we make use of android:pathPrefix to navigate to different screens based on context path?

You may opt for a pathPattern in the first 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:scheme="https"
                android:host="www.mycompany.com"
                android:pathPattern="/profile/friendslist$"/>
</intent-filter>

The $ indicates end of string, which would drop the "/profile/friendslist/details" case

OR Rather, go for android:path="/profile/friendslist" which looks for an exact match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM