用于 http 地址的 Android Intent-Filter

标签 android android-activity android-intent android-manifest intentfilter

我正在尝试通过我的应用拦截几个不同的链接,但我在使用 Intent 过滤器数据参数时遇到了问题。

这是我要拦截的两种链接

  1. http://www.domain.com/#id=abcdef123346
  2. http://www.domain.com/social/landing/abcdef123456

我已经决定有一个单独的 Activity 来拦截两个链接并使用 java 正则表达式来启动正确的 Activity 。但是,如果不捕获 http://www.domain.com/abc123 之类的内容,我似乎无法仅捕获这两种格式

<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="www.domain.com"
                android:pathPattern="/#id.*" />
        </intent-filter>

这是我目前试图拦截的类型 1,但由于某种原因它不起作用。

此 Intent 过滤器正确拦截类型 2

<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" />
            <data android:host="domain.com" />
            <data android:host="www.domain.com" />
            <data android:pathPrefix="/share/web" />
            <data android:pathPrefix="/social/landing" />
        </intent-filter>

谢谢,

最佳答案

我认为 pathPattern 匹配的字符串是“/”,而“#id...”被省略了,因为它是 fragment 的一部分。如果您改用 http://www.domain.com/id/abcdef123456,pathPattern 可以匹配“/id/.*”,因为它是路径的一部分。

关于用于 http 地址的 Android Intent-Filter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6179776/

相关文章:

android - 使用设计支持库的android底部导航菜单中超过3个项目

Android: addview()- 在 Activity 之上添加新 View

安卓 : Getting "Cannot reload AVD list:" error at the time of execution

android - 如何添加分享到 Instagram 快拍的选项?

android - 在同一 fragment 中合并 Map 和 ListView

android - “非法状态异常 : Only fullscreen activities can request orientation

android - FLAG_TRANSLUCENT_NAVIGATION 在横向模式下不可用?

java - 菜单选项不适用于 Android 2.2 和 2.3.5

android - onCreateOptionsMenu 何时在启用 ActionBar 的 Activity 中发生?

java - 通过 Firebase 单击通知获取 Intent Extra