android - 如何处理不同 Activity 的应用程序链接?

标签 android intentfilter

例如,我有域 example.com。它可以与 httpshttp 一起使用。我有这项服务的 Android 客户端。我希望客户端能够打开多种链接类型。他们在这里:

http://example.com
https://example.com
http://example.com/app
https://example.com/app

这四个应该是在ListActivity上打开的。但也有其他链接,如:

https://testask.com/i/__some_guid__
https://testask.com/item/__some_guid__
and relevant link without https

它们应该在另一个 Activity 上打开,例如 DetailsActivity。目前我有以下 DetailsActivity 的 Intent 过滤器:

<intent-filter
    android:autoVerify="true"
    tools:targetApi="m">
    <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" />
    <data android:scheme="https" />
    <data
         android:host="@string/root_host_endpoint"
         android:pathPattern="/i/.*" />
    <data
         android:host="@string/root_host_endpoint"
         android:pathPattern="/item/.*" />
</intent-filter>

看起来它工作正常。但我不明白,如何添加 MainActivity Intent 过滤器以指向根主机 url 并且不与 DetailsActivity Intent 过滤器重叠。

最佳答案

您可以有多个具有不同 Intent 过滤器的 Activity 。您可以使用操作/类别/数据来区分您的 Intent 过滤器。在您的情况下,您必须调整数据配置以使其处理不同的 Intent 。因此 MainActivity/ListActivity 将具有与 DetailsActivity 不同的数据配置

关于android - 如何处理不同 Activity 的应用程序链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44513286/

相关文章:

android - 如何从 Intent 中获取文件名?

android - 打开特定 URL 后将用户从浏览器重定向到我的应用程序

android - 通过浏览器中的 URL 打开 Android 应用程序

android - 在服务中为什么不声明 Intent 过滤器?

android - fragment与activity之间的通信

android - Flutter:任务 ':app:checkDebugAarMetadata' 执行失败。无法解析配置 ':app:debugRuntimeClasspath' 的所有文件

android - Termux sh下"function: not found"错误

php - PubNub 推送通知

android - 如何在android中找到一个位置是否在给定的两个位置之间?