11

I'm creating an rss aggregator for my Android phone. I'd like to be able to subscribe to an rss feed from the browser since most websites have a subscribe via rss button.

How can I build an intent filter to receive those links?

This question was similar and showed how to create an intent filter to handle browser links: Make a link in the Android browser start up my app?

However, I don't know how to make it specific to rss feeds. As an attempt I tried this filter:

        <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>

Am I on the right track? What should I be filtering on?

Community
  • 1
  • 1
CodeFusionMobile
  • 14,812
  • 25
  • 102
  • 140
  • 1
    Just a short reminder: don't assume the path can be given as a regex just because you frequently see ".*". The syntax is very limited. See http://developer.android.com/guide/topics/manifest/data-element.html for the few details about that. – xmjx Aug 04 '11 at 07:49

4 Answers4

21

These 3 filters seem to be the ones used by GoogleListen and GoogleReader apps:

<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>
  • This saved me an hour of trying around. Would give +10 if possible. Just out of curiosity: How did you find out which filters Google Listen and Google Reader were using? – sven Aug 25 '13 at 18:11
7

Turns out there's a lot of different ways podcasts can be set up so each intent filter will only work for some of them. A lot of different filters need to be used to get the desired effect over most subscribe links.

Here's some of the filters I found that worked:

<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>
CodeFusionMobile
  • 14,812
  • 25
  • 102
  • 140
  • why do app gets closed after getting the url of website through the intent filters? i mean in my app, when i use intent filter to add get website url, it shows in textview but gets closed and back to the browser app from where i clicked on the link – Maulik Sheth Sep 22 '13 at 21:57
3

Am I on the right track?

Yes. However:

  • You don't need the scheme
  • You are missing the android: prefix in front of scheme, anyway
  • type should be android:mimeType

Here is a sample application that demonstrates, among other things, responding to links on PDF files.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

Could it be that the server doesn't send the right mimetype?

Experiment by adding:

<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>

Edit: It's a bit tricky to compose the right set of intent-filters, there's a lot of early returns in the matching algorithm:
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/IntentFilter.java

In your case, the mimetype must match exactly which is 'application/rss+xml' do your sources return that mimetype in the message header?

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

Try to:

  1. Make broader filters
  2. Add multiple filters.
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Phyrum Tea
  • 2,623
  • 1
  • 19
  • 20