gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:17:24 26 4
gpt4 key购买 nike

我已阅读有关在 android studio 3.0 中创建深层链接和使用应用程序链接服务的文档。它非常简单易懂,但是当我的 URL 没有前缀路径时我遇到了一点问题。示例:

https://example.com/<this is my premalink>/amp

没有前缀,直接是url pattern。当我使用正则表达式时

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

它不起作用,错误显示为

The URL doesnt map to any activity

当我只使用星标时,例如:

https://example.com/*/amp

它的显示似乎有错误。我卡在了这一步,我已经检查了很多关于深度链接的教程,并且总是使用 pathPrefix 而不是 pathPattern。

最佳答案

Android 深度链接的一个常见缺点是它仅支持 *. 正则表达式字符。在 Android docs 中提到和 can be observed in source code .

来自文档:

For more information on these three types of patterns, see thedescriptions of PATTERN_LITERAL, PATTERN_PREFIX, andPATTERN_SIMPLE_GLOB in the PatternMatcher class.

PATTERN_SIMPLE_GLOB 用于正则表达式,表示仅匹配

/*** Pattern type: the given pattern is interpreted with a* simple glob syntax for matching against the string it is tested against.* 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;

因此只允许使用 *.\。使用其他模式文字 +,? 等;将导致失败。

要么你可以使用你的工作选项,要么你可以使用

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

....* 至少 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>

关于android - 如何使用 PathPattern 来创建 DeepLink Apps Android?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52436111/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com