2013-05-09 63 views
1

有很多示例代碼使用IntentFilter,方案"http"mimeType集合。查看答案Handling MIME type that is the result of a browser POST in AndroidIntent filter for browsing XML (specifically rss) in androidHow to open my Android app when rss link is opened in browser?MIME類型意圖過濾器是否適用於HTTP URL?

具體使用情況而我是RSS鏈接,像那些過去的兩個問題,但RSS提要我想攔截沒有我可以pathPattern有效匹配的路徑,我無法控制。我已經使用最初是從谷歌閱讀器APK中提取相同的意圖過濾器的嘗試:

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

但是當我通過點擊瀏覽器指向這樣一個文件的鏈接進行測試,Chrome現在瀏覽該文件。我安裝了Google閱讀器,而且也沒有響應意圖。如果我將mimeType行替換爲與測試網址匹配的pathPattern,我的應用將收到該意圖。通過向服務器發送HEAD請求,我已驗證URL的Content-Type是作爲「application/xml」發送的。測試設備是ROM ROM上的Nexus 10。

我通過恢復mimeType篩選器並在shell中從am start啓動URL進行了另一項測試。這條命令,僅指定URL,

am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d http://my.test/url 

推出的瀏覽器,但是當我指定該命令中明確的類型,

am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -t application/xml -d http://my.test/url 

這表明我的意圖選擇器我的應用程序和谷歌閱讀器。這似乎證實過濾器正在生效,但Chrome在沒有提供類型的情況下啓動了意圖,而意向解析器沒有從URL中找到該類型(對於content: URI的方式),但似乎並不合理這麼多人可能會使用並推薦不可能工作的意圖過濾器。有沒有人有明確的答案:<data android:scheme="http" android:mimeType="..." />有什麼用意圖過濾器?

回答

0

根據另一個StackOverflow答案,瀏覽器檢查Content-Disposition標頭,如果它指示附件,甚至不檢查意圖過濾器。

這可能是你面臨的問題嗎?

https://stackoverflow.com/a/8770360/304876

+0

您鏈接到的答案是有人**猜測**這就是發生了什麼事。它肯定不是在這種情況下:RSS文件不附帶「Content-Disposition:附件」標頭。 – 2013-07-10 12:40:21