Intent filter for browsing XML (specifically rss)

2019-03-21 19:15发布

问题:

I have an activity that I want to run every time the user goes to an xml (specifically rss) page in the browser (at least assuming the user get's it from the list of apps that can support it).

I currently already have the current intent filter:

    <activity android:name=".activities.EpisodesListActivity"
        android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <category android:name="android.intent.category.BROWSABLE"></category>
            <category android:name="android.intent.category.DEFAULT"></category>
            <action android:name="android.intent.action.VIEW"></action>
            <data android:scheme="http"></data>
        </intent-filter>
    </activity>

Now as you can guess, this is an evil intent, as it wants to open whenever a page is requested via http. However, when I ad the line:

<data android:mimeType="application/rss+xml"></data>

to make it:

    <activity android:name=".activities.EpisodesListActivity"
        android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <category android:name="android.intent.category.BROWSABLE"></category>
            <category android:name="android.intent.category.DEFAULT"></category>
            <action android:name="android.intent.action.VIEW"></action>
            <data android:scheme="http"></data>
            <data android:mimeType="application/rss+xml"></data>
        </intent-filter>
    </activity>

The application no longer claims to be able to run rss files.

Also, if I change the line to:

<data android:mimeType="application/xml"></data>

It also won't work (for generic xml file even).

So what intent filter do I need to make in order to claim that the activity supports rss.

(Also, bonus points if you can tell me how I know what URL it was the user opened. So far, I've always sent that information from one activity to the other using extras).

Thank you for your help

回答1:

try this as your intent-filter

        <intent-filter android:label="@string/app_name">
            <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="application/rss+xml" />
            <data android:mimeType="application/atom+xml" />
            <data android:mimeType="application/xml" />
            <data android:mimeType="text/xml" />
        </intent-filter>