简体   繁体   English

如何使用 PathPattern 来创建 DeepLink Apps Android?

[英]How to use PathPattern in order to create DeepLink Apps Android?

I have read documentation about create an deeplink and use app linking service in android studio 3.0.我已阅读有关在 android studio 3.0 中创建深层链接和使用应用链接服务的文档。 its pretty simple and easy to understand, but I have little bit problem when my URL has no prefix path.它非常简单且易于理解,但是当我的 URL 没有前缀路径时,我会遇到一些问题。 example :例子 :

https://example.com/ /amp https://example.com//amp

there is no prefix, its directly url pattern.没有前缀,它直接是 url 模式。 when i use regex当我使用正则表达式时

^[a-z0-9]+(?:-[a-z0-9]+)*$ ^[a-z0-9]+(?:-[a-z0-9]+)*$

it doesnt works, error shown as它不起作用,错误显示为

The URL doesnt map to any activity该 URL 未映射到任何活动

when i use only star, like :当我只使用星星时,例如:

https://example.com/ */amp https://example.com/ */amp

its show seem error.它的显示似乎错误。 i got stuck in this step, I've check much tutorial about deeplink, and there always use pathPrefix instead of pathPattern.我在这一步卡住了,我检查了很多关于 deeplink 的教程,并且总是使用 pathPrefix 而不是 pathPattern。

please somebody help me.请有人帮助我。 thankyou so much太感谢了

It's a common drawback in android deep linking that it only support * and . android 深度链接的一个常见缺点是它只支持*. regex character.正则字符。 It's mentioned in Android docs and can be observed in source code .它在Android 文档中提到, 可以在源代码中观察到

From docs:从文档:

For more information on these three types of patterns, see the descriptions of PATTERN_LITERAL, PATTERN_PREFIX, and PATTERN_SIMPLE_GLOB in the PatternMatcher class.有关这三种模式的更多信息,请参阅 PatternMatcher 类中对 PATTERN_LITERAL、PATTERN_PREFIX 和PATTERN_SIMPLE_GLOB的描述。

PATTERN_SIMPLE_GLOB is for regex and it says only match PATTERN_SIMPLE_GLOB 用于正则表达式,它表示只匹配

/** * Pattern type: the given pattern is interpreted with a * simple glob syntax for matching against the string it is tested against. /** * 模式类型:使用 * 简单的 glob 语法解释给定的模式,以匹配它所测试的字符串。 * In this syntax, you can use the '*' character to match against zero or * more occurrences of the character immediately before. * 在此语法中,您可以使用'*'字符来匹配零个或 * 多个紧接在前面的字符。 If the * character before it is '.'如果它前面的 * 字符是'.' it will match any character.它将匹配任何字符。 The character * '\\' can be used as an escape.字符 * '\\'可以用作转义符。 This essentially provides only the '*' * wildcard part of a normal regexp.这本质上只提供普通正则表达式的 '*' * 通配符部分。 */ */

public static final int PATTERN_SIMPLE_GLOB = 2;

So only * , .所以只有* , . and \\ are allowed.\\是允许的。 Usage of other pattern literal +,?使用其他模式文字+,? etc;等等; will result in failure.会导致失败。

Either you can use your working option or you can use您可以使用您的工作选项,也可以使用

https://example.com/./....*

....* at least 3 characters then .* mean 0 or more characters ....*至少 3 个字符然后.*表示 0 个或更多字符

<activity
    android:name="packagename.ActivityName" >
    <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.example.com"
              android:pathPattern="/./....*" />
        <!-- note that the leading "/" is required for pathPrefix-->
    </intent-filter>
</activity>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM