简体   繁体   English

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

[英]How to open my Android app when rss link is opened in browser?

I'm creating an rss aggregator for my Android phone. 我正在为我的Android手机创建一个rss聚合器。 I'd like to be able to subscribe to an rss feed from the browser since most websites have a subscribe via rss button. 我希望能够从浏览器订阅RSS订阅源,因为大多数网站都通过rss按钮订阅。

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? 这个问题类似,并展示了如何创建一个处理浏览器链接的意图过滤器: 在Android浏览器中创建一个链接启动我的应用程序?

However, I don't know how to make it specific to rss feeds. 但是,我不知道如何使它特定于rss feed。 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? 我应该过滤什么?

These 3 filters seem to be the ones used by GoogleListen and GoogleReader apps: 这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>

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>

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 无论如何,你在scheme前面缺少android:前缀
  • type should be android:mimeType type应该是android:mimeType

Here is a sample application that demonstrates, among other things, responding to links on PDF files. 这是一个示例应用程序 ,它演示了响应PDF文件的链接等。

Could it be that the server doesn't send the right mimetype? 可能是服务器没有发送正确的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: 编辑:组合正确的intent-filters集有点棘手,匹配算法中有很多早期的回报:
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/content/IntentFilter.java 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? 在你的情况下,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"));

Try to: 尝试:

  1. Make broader filters 制作更广泛的过滤
  2. Add multiple filters. 添加多个过滤器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的Phonegap-App如何在Android浏览器中打开链接? - How can my Phonegap-App open a Link in the Android Browser? Android-已打开我的应用程序时在我的应用程序中打开URL - Android - open url in my app when my app is already opened Android Rss Feed(在不在浏览器中的应用程序内打开) - Android Rss Feed (open inside an app not in a browser) Android 浏览器中的深层链接无法打开应用程序 - App is not opened by deep link in Android browser 即使我的应用程序处理了意图,如何在 Android 上强制在浏览器中打开通用链接 - How to force open a universal link in the browser on Android, even if my app handles the intent 当用户单击Facebook或某些应用程序中的链接并在我的Android应用程序中显示该链接时,如何打开我的Android应用程序? - How to open my android app when a user clicks a link in facebook or some app and display that link in my android app? 当我在应用浏览器中的android webview中打开链接时,如何在左上方放置关闭按钮 - when i open a link in android webview in app browser how can i put close button on top left 如何从C#Xamarin android中的浏览器链接打开应用程序? - How to open app from browser link in c# Xamarin android? 如何在 Android 浏览器中创建我网站的链接启动我的应用程序但当链接有某个部分时不启动 - How to make a the links of my website in the Android browser start up my app but not when the link has a Certain part 在Android上使用[ionic Mobile App或浏览器]打开链接 - Open Link With [ ionic Mobile App or browser ] on android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM