Intent-filter无法在浏览器中运行

时间:2012-05-29 12:22:09

标签: android android-intent intentfilter

我正在使用一个带有类似于here所述的意图过滤器的Activity,以便能够拦截浏览器中的点击,并为用户提供打开我的应用的选项。这是我AndroidManifest.xml的代码:

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

如果我在浏览器中输入http://www.scompt.com,则无效。正常加载页面。

如果我在命令行中输入以下任一命令,那么我会在应用程序和浏览器之间获得标准选择器,正如我所期望的那样。

adb -d shell am start -d http://www.scompt.com -a android.intent.action.VIEW
adb -d shell am start -d http://www.scompt.com

我还有什么其他地方可以让它发挥作用吗?我已经验证了我在使用开源hubroid做了什么,而且我似乎在做同样的事情。

4 个答案:

答案 0 :(得分:9)

关于意图,用户在浏览器中键入URL并跟踪网页,电子邮件等链接之间存在明显差异。

如果您关注浏览器网页上的链接或电子邮件中的链接,则会按预期触发意图。

但是,当用户在其浏览器的地址栏中键入URL时,Android认为用户特别希望该URL在浏览器中打开,因此不会触发意图。

因此,如果您要测试URL和目标过滤器,则需要设置一个带有超链接的静态网页,或者向您的手机发送电子邮件。

当您考虑它时,此系统的工作方式与Windows中的默认浏览器行为类似。想象一下,您的默认浏览器是Chrome,但您也安装了Firefox。如果您点击电子邮件中的链接,它将在Chrome中打开。但是,如果您打开Firefox并在地址栏中输入一个URL并点击它就不能在Chrome中打开,因为很明显您希望在Firefox中打开该URL。

答案 1 :(得分:2)

http://example.com不是http://www.example.com

尝试在浏览器中输入http://www.example.com,看看是否有效。

这是适用于我的清单代码:

<activity
    android:name="MY_APP"
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data
            android:host="MY_HOST"
            android:scheme="MY_SCHEME" />
    </intent-filter>
</activity>

答案 2 :(得分:1)

我遇到了与2014年1月28日Chrome浏览器完全相同的问题。 在这里查看我的答案

Launch custom android application from android browser

答案 3 :(得分:0)

将pathPatterns添加到数据标记:

from syntax import List
from syntax.List import List as OriginList

List is OriginList # True