意图过滤器和android:pathPattern [英] Intent Filters and android:pathPattern

查看:166
本文介绍了意图过滤器和android:pathPattern的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序,我想处理使用以下模式链接:

In my application, I want to handle links that use the following pattern:

方案://主机/文件夹1 /文件夹2 / folder3 / folder4 /条

我得到它暂时无法工作,通过使用以下内容:

I got it to work temporarily, by using the following:

<intent-filter>
    <data android:scheme="http" />
    <data android:host="www.laprensa.com.ni" />
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

但是,正如你可能想象,打开与方案开头的链接://主机,我想确保我只能拿起那些有如上所述图案,其中所述页是主机内4个文件夹。

However, as you may imagine that opens any link that starts with scheme://host, and I want to make sure I only pick up on those that have the above stated pattern, where the page is 4 folders inside the host.

另一个小问题是,文件夹的名称是绝不相同,因此,我不能简单地用的android:路径。另外值得一提的是,的android:路径preFIX 是不一样的,因为前三个文件夹中日期相关的。

Another little problem is that the folder names are never the same, and therefore I cannot simply use android:path. It's also worth noting that the android:pathPrefix is not the same, as the first three folder are date related.

例如,网址是strucutred是这样的:

For instance, the urls are strucutred something like this:

方案://主机/年/月/日/ articleType /条

我一直在阅读关于如何使用 Android版Google文档和问题:pathPattern ,但我真的不明白我应该键入

I've been reading the docs and questions on how to use android:pathPattern but I really don't understand what I'm supposed to type in.

任何想法?

谢谢!

修改

建议后,我想:

的android:pathPattern =/.*/.*/.*/.*/.*

这里,每个'*'重新presented一个文件夹,但似乎仍然拿起不在文章的其他网址。例如,下面是两个不同的网址:

Where each '.*' represented a folder but that seems to still pick up the other URLs that are not articles. For example, here are two different urls:

网址我想处理:

http://www.laprensa.com.ni/2013/05/10/vida/145996-lionel-richie-defiende-a

网址我不希望处理

Url I don't want to handle

http://www.laprensa.com.ni/2013/05/10/vida/

我想这里的问题是,它们都具有水平相同数量的,唯一的区别是,一个后,去年/,任何其他居然有东西想法我能试试吗?我也尝试增加一个'/.*但完全停止工作和停止的应用程序处理的任何链接期间:(

I guess the problem here is that they both have the same amount of levels, the only difference is that one actually has something after that last '/', any other ideas I can try? I did try adding one more '/.*' but that stopped working completely and the app stopped handling any links period :(

推荐答案

您应该添加完全的android:pathPattern 属性来配置你定义。
正如 Android文档, Android的:pathPattern 可以包含以下通配符构建简化常规的前pressions:

You should add exactly the android:pathPattern attribute to configuration you defined. As reported in Android documentation, android:pathPattern can contain following wildcards for building simplified regular expressions:


  • 星号(*)的0序列匹配到马上preceding性格许多发生。

  • 句点后跟一个星号(*)的0任何序列匹配的字符。

在您的情况:

<data android:scheme="http"
      android:host="www.laprensa.com.ni"
      android:pathPattern="/.*/.*/.*/.*/.*" />

如果每个*重新present文件夹名称。

Where each .* represent a folder name.

这篇关于意图过滤器和android:pathPattern的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆