java - 添加网站不同子目录的不同 Intent

标签 java android android-intent

假设我的网站位于:https://www.domain.tld/

是否可以添加不同的 Intent :

https://www.domain.tld/将打开一些 Activity

https://www.domain.tld/directory 1 将打开一些其他 Activity

https://www.domain.tld/direcotry2将打开一些其他 Activity ...等等?

我有一个基于 gradle 的 Android Studio 项目,主要用 Java 编写,如果有帮助的话。

此外,到目前为止,我的 Intent 如下:

https://www.domain.tld/打开一些 Activity

https://subdomain.domain.tld/打开一些其他 Activity 。

为了实现此目的,我使用了 Android Studio 的 URL 映射编辑器,如下所示:

我已添加https://www.domain.tld作为主持人,我选择了选项路径并将其文本字段留空并将其映射到所需的 Activity 。

我曾考虑过尝试 pathPrefix 和 pathPattern,但是,我认为它不适用于我的情况。如果我只需要映射子目录,这很容易,但是,我需要为我的网站的根目录维护一个单独的 Intent 。因此,路径、pathPrefix 和 pathPattern 将包含我的根目录,因此它可能不起作用(这是一个猜测)。另外,我不太确定 pathPattern 的含义。

因此,我正在考虑将子域移动到我网站的子目录中。仅当可以处理我上面提到的 Intent 时,我才会这样做。

我认为,有可能,只是不太清楚,如何实现。

最佳答案

关于pathPattern你可以检查documentation .

以下对 pathPattern 的支持将帮助您仅处理主机 URL。

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

根据您的需要,Android Studio 的 URL 映射编辑器将帮助您为 URL 创建以下 Intent 过滤器,以便打开特定的 Activity。 更多详情请查看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>

关于java - 添加网站不同子目录的不同 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51341460/

相关文章:

java - sessionFactory.getCurrentSession() 正在与 @Transactional 一起使用,但 sessionFactory.openSession() 不是

java - 在简历上重新加载 SharedPreferences? (或如何刷新/重新加载 Activity )

android - 棉花糖应用权限撤销通知?

android - 无法正确获取 "android.intent.action.SEND" Intent 的路径

android - 恢复 Top Activity 而不是启动 Launcher Activity

java - 使用 Flying Saucer 将 HTML 转为 PDF : Internal CSS showing in PDF page

java - PDFBox 避免 关闭前是否要保存更改

android - 如何在android中进行本地通知?

Android:从 View 中返回一个字符串?

java - 从后台线程中的另一个类更新 GUI