Michael Spitsin Michael Spitsin - 1 month ago 22
Android Question

Open diffenent Activities on pathPrefixes /abc and /abc/def

I have two urls. For example:


  1. http://host.com/abc/12345

  2. http://host.com/abc/def/12345



Where an
12345
- is some id.

I want to open different activities for these urls.

Currently I have next implementation in AndroidManifest.xml:

<activity
android:name=".ui.activities.Activity1"
android:windowSoftInputMode="adjustResize">
<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="host.com" android:pathPrefix="/abc"/>
</intent-filter>
</activity>
<activity
android:name=".ui.activities.Activity2"
android:windowSoftInputMode="adjustResize">
<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="host.com" android:pathPrefix="/abc/def"/>
</intent-filter>
</activity>


First url works great: when I tap on it android suggest me to use some other apps or my Activity1.

But problem appears when I tap on second url: android suggest me to use some other apps or my Activity1 or my Activity2.

So my question is: is there a way to exclude Activity1 from list of suggestions.

I tried to play with
pathPattern
and tried to googling how to exclude url from IntentFilter but I failed.

Answer

I cannot think of a better approach, but this works:

<activity
    android:name=".ui.activities.Activity1"
    android:windowSoftInputMode="adjustResize">
    <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:host="test.com"
            android:pathPattern="/abc/1.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/2.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/3.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/4.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/5.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/6.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/7.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/8.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/9.*"
            android:scheme="http"/>
        <data
            android:host="host.com"
            android:pathPattern="/abc/0.*"
            android:scheme="http"/>
    </intent-filter>
</activity>
<activity
    android:name=".ui.activities.Activity2"
    android:windowSoftInputMode="adjustResize">
    <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:host="host.com"
            android:pathPattern="/abc/def/.*"
            android:scheme="http"/>
    </intent-filter>
</activity>
Comments