使用Android意图过滤器路径匹配文件名 [英] Matching file name using Android intent-filter pathPattern
问题描述
我需要匹配以/*-u.html
结尾的网址,例如 https://www.example.com/something/whatever-u.html
.
I need to match urls ending in /*-u.html
, e.g. https://www.example.com/something/whatever-u.html
.
我已经尝试过 android:pathPattern ="/.*- u.html"
,该代码适用于上述网址,但如果网址中的其他任何地方都没有连字符,则无法使用,例如 https://www.example.com/some-thing/whatever-u.html
.起初,我认为连字符有一些特殊之处,但是后来我意识到,任何跟随.*
.
I've tried android:pathPattern="/.*-u.html"
, which works for the above url, but it doesn't work if there's a hyphen anywhere else in the url, e.g. https://www.example.com/some-thing/whatever-u.html
. At first I thought there was something special about the hyphen character, but then I realised the same happens with any character that follows the .*
.
我尝试了许多其他组合,但是找不到可靠地匹配上述url格式的组合.我知道PatternMatcher是有限的,但是我认为应该可以匹配它?
I've tried many other combinations but can't find one to reliably match the above url format. I know that PatternMatcher is limited, but I assume it should be possible to match this?
这是一个有关此问题的视频,使用下面的PraveenSP答案中建议的模式.
Here's a video of the issue, using the patterns suggested in PraveenSP's answer below.
推荐答案
尝试这样做
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data
android:host="*.yourhost.com"
android:pathPattern="/.*\\/.*-u.html"
android:scheme="https" />
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data
android:host="*.yourhost.com"
android:pathPattern=".*-u.html"
android:scheme="https" />
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data
android:host="*.yourhost.com"
android:pathPattern="/.*\\/.*-.*-u.html"
android:scheme="https" />
</intent-filter>
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<action android:name="android.intent.action.VIEW" />
<data
android:host="*.yourhost.com"
android:pathPattern="/.*\\/.*-.*-u.html"
android:scheme="https" />
</intent-filter>
经过测试的案例: https://www.example.com/some-thing/whatever-u.html
https://www.example.com/something/whatever-u.html
https://www.example.com/something/what-ever-u.html
https://www.example.com/some-thing/what-ever-u.html
Tested cases :
https://www.example.com/some-thing/whatever-u.html
https://www.example.com/something/whatever-u.html
https://www.example.com/something/what-ever-u.html
https://www.example.com/some-thing/what-ever-u.html
这篇关于使用Android意图过滤器路径匹配文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!