Hrishikesh Kokate
Hrishikesh Kokate

Reputation: 1225

Add different intents of different sub-directories of the website

Say I have my website at: https://www.domain.tld/

Is it possible to add different intents in the sense:

https://www.domain.tld/ will open some activity

https://www.domain.tld/directory 1 will open some other activity

https://www.domain.tld/direcotry2 will open some other activity... and so on?

I have a gradle-based Android Studio project written mainly in Java, if that helps.

Also, as of now, I have an intent as follows:

https://www.domain.tld/ opens some activity

https://subdomain.domain.tld/ opens some other activity.

To accomplish this, I have used Android Studio's URL Mapping Editor as follows:

I have added https://www.domain.tld as the Host, I have chosen the option path and left its text field blank and mapped it to the required activity.

I have thought about trying pathPrefix and pathPattern, but, I don't think it'll work in my case. If I had to map just the sub-directories, it was easy, but, I need to maintain a seperate intent for the root directory of my website. So, the path, pathPrefix as well as pathPattern, will contain my root-directory and so, it might not work (this is a guess). Also, I'm not very sure about what pathPattern means.

So, I'm thinking of moving the sub-domain to a sub-directory in my website. I'll do so, only if it's possible to handle the intents as I have mentioned above.

I think, it's possible, just don't know very well, how.

Upvotes: 0

Views: 62

Answers (1)

Bharath Kumar
Bharath Kumar

Reputation: 541

Regarding pathPattern you can check the documentation.

The below support for pathPattern would help you in to handle the host URL only.

An asterisk ('*') matches a sequence of 0 to many occurrences of the immediately preceding character.

As per your needs, Android Studio's URL Mapping Editor will help you to create the below intent filters for the URLs in order to open a specific Activity. More details is available here.

     <activity
        android:name=".MainActivity"
        <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="www.domain.tld"
                android:scheme="https" 
                android:pathPattern="/*" />
        </intent-filter>
    </activity>

    <activity
        android:name=".Main2Activity"
        <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.domain.tld"
                android:pathPrefix="/directory1" />
        </intent-filter>
    </activity>

    <activity
        android:name=".Main3Activity"
        <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.domain.tld"
                android:pathPrefix="/directory2" />
        </intent-filter>
    </activity>

Upvotes: 1

Related Questions