How to catch/listen on android web browser downloa

2019-02-24 08:42发布

问题:

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.