0

I am trying to write an intent filter that will allow my app to open files with extension ".mathref". Following the advice here, I wrote my filter like this:

        <!-- 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>

However, it is not filtering! That is, if the user taps on any file in their email, regardless of the extension, it lists my app as an option for opening the file.

How can I fix that?

Community
  • 1
  • 1
William Jockusch
  • 26,421
  • 48
  • 170
  • 299

2 Answers2

0

Actually, the question you linked has the answer

In the code provided, there's a comment there:

<!--
 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, you have yours set to application/* which will match everything

Community
  • 1
  • 1
Jeeter
  • 4,960
  • 3
  • 41
  • 64
0

How can I fix that?

You don't. There is no requirement for a content Uri to have any particular file extension. Similarly, there is no requirement for a URL in a Web browser to have any particular file extension. As with Web browsers, Android relies far more on MIME types.

If you expect that Web servers will know to serve up your desired document format with a certain MIME type, or if you expect that mail clients will know to use a certain MIME type for attachments of your document format, use that MIME type in your <intent-filter>, rather than application/*.

Otherwise, accept any Uri as input, and validate the content is in your desired document format. Or, do not implement ACTION_VIEW.

CommonsWare
  • 910,778
  • 176
  • 2,215
  • 2,253