如何在浏览器中打开rss链接时打开我的Android应用程序?

时间:2011-02-04 18:37:01

标签: android rss android-intent intentfilter

我正在为我的Android手机创建一个rss聚合器。我希望能够从浏览器订阅RSS订阅源,因为大多数网站都通过rss按钮订阅。

如何构建一个意图过滤器来接收这些链接?

这个问题很相似,并展示了如何创建一个处理浏览器链接的意图过滤器: Make a link in the Android browser start up my app?

但是,我不知道如何使其特定于rss feed。 作为尝试,我尝试了这个过滤器:

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <data android:mimeType="application/rss+xml" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" /> 
        </intent-filter>

我是否在正确的轨道上?我应该过滤什么?

4 个答案:

答案 0 :(得分:21)

这3个过滤器似乎是GoogleListen和GoogleReader应用使用的过滤器:

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http"/>
    <data android:host="*"/>
    <data android:pathPattern=".*\\.xml"/>
    <data android:pathPattern=".*\\.rss"/>
</intent-filter>

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http"/>
    <data android:host="feeds.feedburner.com"/>
    <data android:host="feedproxy.google.com"/>
    <data android:host="feeds2.feedburner.com"/>
    <data android:host="feedsproxy.google.com"/>
</intent-filter>

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="http"/>
    <data android:mimeType="text/xml"/>
    <data android:mimeType="application/rss+xml"/>
    <data android:mimeType="application/atom+xml"/>
    <data android:mimeType="application/xml"/>
</intent-filter>

答案 1 :(得分:7)

原来可以通过很多不同的方式设置播客,因此每个意图过滤器仅适用于其中一些。需要使用许多不同的过滤器来获得大多数订阅链接所需的效果。

以下是我发现的一些过滤器:

<intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="itpc" />
                <data android:scheme="pcast" />
                <data android:scheme="feed" />
                <data android:scheme="rss" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*xml" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*rss" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*feed.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*podcast.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*Podcast.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*rss.*" />
                <data android:scheme="http" android:host="*"
                    android:pathPattern=".*RSS.*" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:mimeType="text/xml" android:scheme="http" />
                <data android:mimeType="application/rss+xml" android:scheme="http" />
                <data android:mimeType="application/atom+xml" android:scheme="http" />
            </intent-filter>

答案 2 :(得分:3)

  

我是在正确的轨道上吗?

是。但是:

  • 您不需要方案
  • 您在android:前面缺少scheme前缀,无论如何
  • type应为android:mimeType

Here is a sample application除其他外,还演示了对PDF文件链接的响应。

答案 3 :(得分:1)

可能是服务器没有发送正确的mimetype吗?

通过添加实验:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.BROWSABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="http" />
    <data android:host="*" />
    <data android:pathPattern=".*\\.rss" />
    <data android:pathPattern=".*\\.xml" />
  </intent-filter>

编辑: 组合正确的意图过滤器有点棘手,匹配算法中有很多早期的回报:
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/IntentFilter.java

在你的情况下,mimetype必须完全匹配'application / rss + xml'你的消息来源是否在消息头中返回mimetype?

  URL url = new URL("http://www.engadget.com/rss.xml");
  URLConnection conn = url.openConnection();
  System.out.println("Content-Type:"+conn.getHeaderField("Content-Type"));

尝试:

  1. 制作更广泛的过滤器
  2. 添加多个过滤器。