2011-02-04 87 views
10

我正在爲我的Android手機創建一個rss聚合器。我希望能夠從瀏覽器訂閱rss訂閱源,因爲大多數網站都通過rss按鈕訂閱。如何在瀏覽器中打開rss鏈接時打開我的Android應用程序?

如何構建一個意圖過濾器來接收這些鏈接?

這個問題是相似的,並展示瞭如何創建一個意圖過濾器來處理瀏覽器鏈接: Make a link in the Android browser start up my app?

不過,我不知道如何使它特定RSS提要。 作爲一種嘗試我想這個過濾器:

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

我在正確的軌道上?我應該過濾什麼?

+1

只是提醒:不要假設路徑可以作爲正則表達式給出,只是因爲你經常看到「。*」。語法非常有限。請參閱http://developer.android.com/guide/topics/manifest/data-element.html獲取關於這方面的一些細節。 – xmjx 2011-08-04 07:49:28

回答

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

爲什麼應用程序在獲取url後關閉通過意圖過濾器的網站?我的意思是在我的應用程序中,當我使用intent過濾器來添加獲取網址時,它顯示在textview中,但被關閉並返回到我點擊鏈接的瀏覽器應用程序 – 2013-09-22 21:57:18

3

我在正確的軌道上嗎?

是的。但是:

  • 你不需要的方案
  • 你缺少的scheme前面android:前綴,反正
  • type應該android:mimeType

Here is a sample application演示,除其他事項外,回覆PDF文件上的鏈接。

+0

我作出了更正,但仍然無法讓我的應用程序對鏈接做出迴應 – CodeFusionMobile 2011-02-04 23:05:38

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. 添加多個過濾器。
+0

這也行不通。此外,現在大多數Feed不使用.rss或.xml擴展名,他們只使用一些默認url,有時甚至是一個php頁面。 – CodeFusionMobile 2011-02-28 18:55:35

+0

他們正在使用MIME類型,將數據行替換爲: 2011-02-28 21:09:14

19

這3個過濾器似乎是由GoogleListen和Google閱讀器的應用程序所使用的那些:

<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> 
相關問題