How to catch/listen on android web browser downloads

时间秒杀一切 提交于 2020-01-11 09:27:18

问题


I have my android application that listens for browser intents in order to catch them whenever user click on certain type of URI. More specifically, I want my app to open when user clicked on a hyperlink that point to a torrent file (i.g. http://somewhere/file.torrent).

See below my intent filters from my application 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>

This works well as long as the hyperlink point the file location. BUT - sometimes URLs directly point to the file and is interpreted by the server to return the file to download based on some kind of id like this link http://www.mininova.org/get/13202308 which returns the file back. In that case, my intent-filters doesn't work, and the android browser download the file instead of open my app and passing an intent with the file URI.

Does anyone has a clue on how to get the file URI?

Thanks


回答1:


It is possible that on those cases the http response has the header Content-disposition: as attachment;filename=file.torrent

If that's the case is possible that the browser doesn't even throw an intent.



来源:https://stackoverflow.com/questions/8762600/how-to-catch-listen-on-android-web-browser-downloads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!