【问题标题】:How to catch/listen on android web browser downloads如何捕捉/收听安卓网络浏览器下载
【发布时间】:2012-01-06 18:26:22
【问题描述】:

我的 android 应用程序监听浏览器意图,以便在用户单击某种类型的 URI 时捕获它们。更具体地说,我希望我的应用在用户单击指向 torrent 文件的超链接时打开(例如 http://somewhere/file.torrent)。

请参阅下面我的应用程序 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 吗?

谢谢

【问题讨论】:

    标签: android url android-intent


    【解决方案1】:

    在这些情况下,http 响应的标头 Content-disposition: 可能为 attachment;filename=file.torrent

    如果是这种情况,浏览器甚至不会抛出意图。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 2017-10-02
      • 2015-04-15
      • 1970-01-01
      • 2023-03-08
      相关资源
      最近更新 更多