androiduri-scheme

More precise URI scheme


PROBLEM

I've got multiple schemes that guide user to different parts of application. Problem is that since all of these schemes starts the same, the user have to pick where he want to go from Android application chooser(or w/e that bottom box with aplications is called). I would like for my scheme to be more "precise" in order to avoid forcing user to make this decision.

CODE

Activity1 scheme trigger

 <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="foobar.com" android:pathPrefix="/path/category"/>
     <data android:scheme="foobar" android:host="foobar.com" android:pathPrefix="/path/category"/>
 </intent-filter>

Activity2 scheme trigger

<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="foobar.com" android:pathPrefix="/path"/>
      <data android:scheme="foobar" android:host="foobar.com" android:pathPrefix="/path"/>
</intent-filter>

MY UriSchemes

foobar://foobar.com/path

http://foobar.com/path

foobar://foobar.com/path/category

http://foobar.com/path/category


Solution

  • since the pathPrefix of activity1 is the prefix of the same in Activity1 then there is an ambiguity there - so android wont be able to resolve request for activty1 unambiguously.

    There are a couple of options:-

    1. Make an intermediate DeepLinkActivity with intent filters to capture the basic scheme/host/pathPrefix and use that to process the url manually and forward to the relevant Activity. This gives more flexibility if you have complicated url structure in the future.

    2. Change the url of activity2 to be something unique (if thats possible)

    I would recommend option 1