【发布时间】: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