gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:00:51 24 4
gpt4 key购买 nike

假设我的网站位于: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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com