【问题标题】:Intent filter matching URL意图过滤器匹配 URL
【发布时间】:2015-09-15 23:14:52
【问题描述】:

我已经用不同的 android::path、pathPrefix 等组合尝试了几个小时找到的每个示例,但无法使其正常工作。

我的应用的意图过滤器应如何匹配此 URL,如下所示:“example.com/View/File/xxx”,其中 xxx 是随机文件号?

感谢您的帮助!

【问题讨论】:

    标签: android intentfilter


    【解决方案1】:

    您是否在清单中尝试过:

    <activity android:name=".YourActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"></action>
        <category android:name="android.intent.category.DEFAULT"></category>
        <category android:name="android.intent.category.BROWSABLE"></category>
        <data android:scheme="http" android:host="www.example.com" android:path="/View/File/" android:pathPattern=".*"></data>
    </intent-filter>
    

    然后在你的代码中:

    String data = getIntent().getDataString();
    

    取自here 和Android Manifest Docs。我没有机会对此进行测试,如果它不起作用,请尝试弄乱路径、parthPrefix 和 pathPattern。

    【讨论】:

    • 实际上可能有更好的方法从 URL 中获取数据,而不是“getDataString()”。不过,您必须检查 Intent 文档。
    • 感谢您的回答!我也尝试过这种组合,但它不起作用。 :( 如果我根本不使用 path 或 pathPrefix,那么它可以工作,但会将所有 URL 带到该站点。(根据文档,path、pathPrefix 和 pathPattern 需要以斜杠开头)我会继续尝试不同的组合。
    • 经过多次反复试验,我发现android:pathPattern="/View/File/.*" 有效,这是我可以开始工作的唯一组合。对我来说android:pathPrefix="/View/File/.*" 应该也可以,但它没有。
    猜你喜欢
    • 2016-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多