【问题标题】:Android intent-filter detect url with http get paramsAndroid 意图过滤器使用 http 获取参数检测 url
【发布时间】:2014-06-25 17:15:31
【问题描述】:

我想做一个可以检测像这样的网址的意图过滤器

http://x.xxxx.com/x.php?u=http%3A%2F%2Fwww.xxx.com

但我只想在 url 有“http%3A%2F%2Fwww.xxx.com”时检测它

intent-filter 可以做到这一点吗?

编辑

这是我调用意图启动 url 的代码:

String url = "http://example.com/x.php?u=xxxx";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);

我试过了,但它不起作用:

<data android:scheme="http"  android:host="example.com" 
      android:pathPattern="/x.php?u=xxxx"/>

这也不起作用:

<data android:scheme="http" android:host="example.com" 
      android:pathPattern="/x.php?.*"/>

但是我试过只有这个可以工作:

<data android:scheme="http" android:host="example.com" 
      android:pathPattern="/x.php"/>

我想这里的问题是我不能包含“?” android:pathPattern 中的字符 但是我希望只有当查询字符串 u 参数包含“xxxx”字符串时才能检测到它。

能解决吗?

【问题讨论】:

    标签: android


    【解决方案1】:

    您可以在 AndroidManifest 的 intent-filter 中使用 android:pathPattern。 示例:

    <intent-filter android:label="@string/title_app">
         <data android:pathPattern="*xxx.com*" />
    </intent-filter>
    

    还有一个类似的问题here

    在你的情况下是这样的

    <data android:scheme="http"
          android:host="xxx.com"
          android:pathPattern="/x.php?u=http%3A%2F%2Fwww.xxx.com" />
    

    附:我认为,YouTube 和 Google+ 等标准应用程序使用相同的方法:)

    编辑

    不能用intent filter解析查询参数,回答here

    我已阅读有关Uri 的文档,它说根据RFC 2396 路径 不能包含“?”人物

    2.2。保留字符

    许多 URI 包括由某些组成或分隔的组件 特殊字符。这些字符被称为“保留”,因为
    它们在 URI 组件中的使用仅限于它们的保留
    目的。如果 URI 组件的数据与
    保留用途,则冲突数据必须先转义
    形成 URI。

      reserved    = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
                    "$" | ","
    

    上面的“保留”语法类是指那些字符 在 URI 中允许,但在 URI 中可能不允许
    通用 URI 语法的特定组成部分;它们被用作
    第 3 节中描述的组件的分隔符。

    3 URI 语法组件

    &lt;scheme&gt;://&lt;authority&gt;&lt;path&gt;?&lt;query&gt;

    所以,我假设 pathPattern 不适用于查询部分。

    编辑 2

    谁创造了你试图捕捉的意图?您还是其他应用程序? 可能您可以在没有 uri 的情况下发送纯文本意图吗?

    【讨论】:

    • 谢谢,但还是有问题,请看我的编辑
    • 嗯.. 您可以设置最后一个意图,在调试器下捕获它并查看它的内容。晚上,我可以帮助你,我在我的应用程序中使用了这种方法:)
    猜你喜欢
    • 1970-01-01
    • 2019-01-09
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 2013-05-03
    相关资源
    最近更新 更多