如何在android网页浏览器上下载/收听下载
问题描述:
我有我的android应用程序,它监听浏览器意图,以便在用户点击某种类型的URI时捕获它们。更具体地说,我希望我的应用在用户点击指向torrent文件的超链接时打开(例如,http://somewhere/file.torrent)。如何在android网页浏览器上下载/收听下载
见下面我的意图过滤器,从我的应用程序的AndroidManifest.xml:
<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="application/x-bittorrent"
android:scheme="http" />
</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:host="*"
android:pathPattern=".*\\.torrent"
android:scheme="http" />
</intent-filter>
这只要工作得很好的超级链接点的文件位置。 但有时URL会直接指向该文件,并被服务器解释为基于某种类型的id返回文件以进行下载,如链接http://www.mininova.org/get/13202308,它将文件返回。在这种情况下,我的意图过滤器不起作用,Android浏览器下载文件而不是打开我的应用程序,并将意图传递给文件URI。
有没有人有关于如何获取文件URI的线索?
感谢
答
这可能是在这些情况下,HTTP响应有头Content-disposition:
作为attachment;filename=file.torrent
如果是这样的话有可能是浏览器甚至不扔的意图。