gpt4 book ai didi

android - 奇怪的 Intent 过滤器 pathPattern 行为

转载 作者:搜寻专家 更新时间:2023-11-01 09:24:22 26 4
gpt4 key购买 nike

Documentation states可以在 pathPattern 中使用通配符。

A period followed by an asterisk (".*") matches any sequence of 0 to many characters.

因此,我创建了以下过滤器:

<intent-filter android:priority="600">
<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:scheme="https"/>
<data android:host="*"/>
<data android:pathPattern="/.*.exe"/>
</intent-filter>

但是,它并不对所有以“.exe”结尾的链接“有效”。

适用于这些链接:

https://subdomain.site.org/lite/appinst-lite-vc.exe

https://subdomain.site.org/appinst.exe

不适用于此链接:

https://subdomain.freedownloadmanager.org/5/5.1-latest/app_x86_setup.exe

看来,它不适用于在其 path 部分带有额外点的链接。

我是否遗漏了什么或者是 Android 错误(代码或文档中)?

附言此过滤器捕获所有这些链接:

<intent-filter android:priority="600">
<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:scheme="https"/>
<data android:host="*"/>
<data android:pathPattern="/.*"/>
</intent-filter>

最佳答案

是的,你是对的。是 . 导致了问题。

与正则表达式不同,在路径模式中,匹配将在模式第一个字符的第一个匹配处停止。换句话说,* 匹配是非贪婪的。

一种解决方案是添加多个模式,如下所示。添加的越多,数量或 就越多。 它可以没有问题。

<data android:scheme="http" android:host="*"
android:pathPattern=".*\\.exe" />

<data android:scheme="http" android:host="*"
android:pathPattern=".*\\..*\\.exe" />

<data android:scheme="http" android:host="*"
android:pathPattern=".*\\..*\\..*\\..exe" />

<data android:scheme="http" android:host="*"
android:pathPattern=".*\\..*\\..*\\..*\\.exe" />

另一个解决方案是使用 this图书馆。

关于android - 奇怪的 Intent 过滤器 pathPattern 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51912180/

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