【问题标题】:Add file extension filter in a browsable app在可浏览的应用程序中添加文件扩展名过滤器
【发布时间】:2016-08-27 13:11:13
【问题描述】:

我想为我的可浏览应用程序添加一个文件扩展名过滤器,因为我希望它仅在 url 指向图像(jpg、png、bmp、gif...)时才可浏览

我尝试过android:mimeType="image/*",但它不适用于互联网网址,它只有在它直接指向文件系统中的图像时才有效(使用file://

有没有办法通过http://dmoral.es/assets/image/diffie_hellman.png等文件扩展名过滤url?

这是我在清单中的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:scheme="http" android:mimeType="image/*" />
</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:scheme="https" android:mimeType="image/*" />

</intent-filter>

如果我删除 mimeType 过滤器,它可以用作可浏览应用程序,添加过滤器后它不会用作可浏览应用程序。

【问题讨论】:

  • "但它不适用于 Internet url" -- 请提供minimal reproducible example
  • 我已经编辑了答案。
  • 这不是minimal reproducible example 证明您对android:mimeType="image/*" 的问题。
  • 添加了我的intent-filter 代码
  • 好的。您期望触发这些的用户操作是什么?例如,如果您希望用户单击浏览器中的链接,则浏览器可能会选择自行处理其识别的 MIME 类型的链接,而不是搜索可以查看内容的替代应用程序。

标签: android android-intent filter browsable


【解决方案1】:

最后我设法使用pathPattern 使其工作,如here 所示。

<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.jpg"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.jpeg"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.png"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.bmp"/>
<data android:scheme="https"
                android:host="*"
                android:pathPattern=".*\\.gif"/>

(对于httpshttp

【讨论】:

    猜你喜欢
    • 2013-07-02
    • 1970-01-01
    • 2022-11-10
    • 2015-10-06
    • 2021-12-30
    • 1970-01-01
    • 2010-10-22
    • 2011-04-15
    • 2011-01-10
    相关资源
    最近更新 更多