【问题标题】:Android path pattern in deep linking深度链接中的Android路径模式
【发布时间】:2019-01-01 00:24:03
【问题描述】:

我正在尝试在我的应用程序中建立一个深层链接。我需要支持的路径模式看起来像

网址:www.host.com/somestring-/ 示例:好的 URL:www.host.com/Portland-OR/ 错误网址:www.host.com/Portland-、www.host.com/-OR、www.host.com/-、www.host.com/Por-O

所以我有一组至少 1 个字符或更长的字母数字字符集。然后我有一个“-”,然后是 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" android:host="host.com" android:pathPrefix="/.*-.*/" />
        </intent-filter>

我也阅读了以下文档及其相关的源代码。 https://developer.android.com/reference/android/os/PatternMatcher

任何帮助将不胜感激。谢谢!

【问题讨论】:

  • 这可能超出了&lt;data&gt; 的模式匹配语言所能支持的范围。
  • 可以说“alphanumeric-2characters”吗?
  • 我不知道,抱歉。这是一个非常有限的模式匹配器。

标签: android android-intent intentfilter


【解决方案1】:

您不能在 AndroidManifest.xml 中以静态方式执行此操作,但您可以在 &lt;activity&gt; 或任何包含 &lt;intent-filter&gt; 的组件中的代码中编写自己的编程模式匹配器,方法是通过以下方式提取 Uri 实例intent.getData() 并使用正则表达式或只是通过 - 字符廉价拆分并检查第二部分。

【讨论】:

  • 问题是我不希望所有的 host.com url 都由应用程序处理。使用您提到的解决方案,我必须处理 Android Manifest 中的所有 url,然后在内部我需要解析 url,然后决定如何处理它
  • @LateNightDev 您可以尝试在路径上使用子域而不是模式匹配。像 deeplink.host.com 为您的所有深层链接或使用自定义方案,如 host://deep-link
猜你喜欢
  • 1970-01-01
  • 2019-08-04
  • 1970-01-01
  • 2021-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-06-17
相关资源
最近更新 更多