Android电子邮件意图过滤器不过滤文件扩展名

时间:2016-08-18 16:41:04

标签: android android-intent

我正在尝试编写一个意图过滤器,允许我的应用打开扩展名为#34; .mathref"的文件。根据建议here,我写了这样的过滤器:

        <!-- For email attachments -->
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/*" host="*" />
            <data android:pathPattern=".*\\.mathref"/>
            <data android:scheme="content" />
        </intent-filter>

然而,它不是过滤!也就是说,如果用户点击其电子邮件中的任何文件,无论扩展名如何,它都会将我的应用列为打开文件的选项。

我该如何解决?

2 个答案:

答案 0 :(得分:0)

实际上,question you linked has the answer

在提供的代码中,有评论:

<!--
 Capture content by MIME type, which is how Gmail broadcasts
 attachment open requests.  pathPattern and file extensions
 are ignored, so the MIME type *MUST* be explicit, otherwise
 we will match absolutely every file opened.
-->

the MIME type *MUST* be explicit,您将自己设置为application/*,这将匹配所有内容

答案 1 :(得分:0)

  

我该如何解决?

你没有。 content Uri不需要任何特定的文件扩展名。同样,Web浏览器中的URL不需要具有任何特定的文件扩展名。与Web浏览器一样,Android更依赖于MIME类型。

如果您希望Web服务器知道使用某种MIME类型提供所需的文档格式,或者您希望邮件客户端知道将某种MIME类型用于文档格式的附件,请使用该MIME类型在<intent-filter>,而不是application/*

否则,接受任何Uri作为输入,并验证内容是否为所需的文档格式。或者,不要实施ACTION_VIEW

相关问题