首页 > 解决方案 > 深度链接中的Android路径模式

问题描述

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

URL:www.host.com/somestring-<2letters>/ 示例:好 URL:www.host.com/Portland-OR/ 坏 URL:www.host.com/Portland-、www.host.com/-或, 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

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

标签: androidandroid-intentintentfilter

解决方案


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


推荐阅读