http方案意图过滤器,用于从Web链接到应用程序

时间:2012-07-19 14:00:59

标签: android android-intent intentfilter

这似乎是一个典型的问题,似乎有很多不同的行为,我遇到的问题是我的方案将启动选择器并允许我选择我的应用程序当我点击链接电子邮件或设备上的注释,但如果我点击网页上的链接,我似乎无法启动应用程序,甚至不能获取选择器(我检查了两个浏览器的“默认值”,没有已设定)。

<activity
                android:name=".MyActivity" 
                android:exported="true"
                android:enabled="true">
                <intent-filter>
                    <data android:scheme="http" android:host="www.website.com"/>
                    <data android:scheme="http" android:host="website.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.website.com/share.aspx?id=12345678

使用Chrome和股票浏览器测试运行ICS 4.0.3的GS2。

2 个答案:

答案 0 :(得分:2)

添加android:pathPrefix属性。

<data android:scheme="http" android:host="website.com" android:pathPrefix="/" />

答案 1 :(得分:2)

这就是我最终解决的问题:

<intent-filter>
            <data
                android:host="www.website.com"
                android:pathPattern=".*\\share.aspx"
                android:scheme="http" />
            <data
                android:host="website.com"
                android:pathPattern=".*\\share.aspx"
                android:scheme="http" />

            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.BROWSABLE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

还要将以下内容添加到Activity标记:

android:exported="true"

有两个地址的原因是应用程序可以选择规范域名(有/无www。)。

相关问题