Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple file extension/mimetype intent-filters with one activity

Gents,

I'm trying to get it so that my Android application can respond both to files being opened (via matching their extensions) and to mime-types (so they will work from the browser).

I've followed the advice here:

Android intent filter for a particular file extension?

but still had no luck.

The relevant section from my android manifest file is as follows:

<activity android:name="MuPDFActivity"
              android:label="@string/app_name"
      android:theme="@android:style/Theme.NoTitleBar">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/vnd.ms-xpsdocument"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/pdf"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:mimeType="application/x-cbz"/>
        </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="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.xps"/>
            <data android:host="*"/>
        </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="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.pdf"/>
            <data android:host="*"/>
        </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="file"/>
            <data android:mimeType="*/*"/>
            <data android:pathPattern=".*\\.cbz"/>
            <data android:host="*"/>
        </intent-filter>
    </activity>

As you can see, I would like the app to be invoked for .pdf, .xps, and .cbz files, also files with the relevant mimetypes. Local tests here seem to suggest that the .pdf and application/pdf sections are both working, but try as I might, the .xps (and presumably .cbz) sections are not.

Am I missing something obvious here? Can each Activity only have one mimetype/file pattern?

Any help would be much appreciated.

Thanks,

Robin

like image 730
Robin Watts Avatar asked Feb 09 '12 17:02

Robin Watts


People also ask

Can an activity have multiple intent filters?

However, since a component can have multiple intent filters, an intent that does not pass through one of a component's filters might make it through on another. An <intent-filter> element in the manifest file lists actions as <action> subelements. For example: <intent-filter . . . >

What is intent filters explain intent filters with example?

An intent filter is an expression in an app's manifest file that specifies the type of intents that the component would like to receive. For instance, by declaring an intent filter for an activity, you make it possible for other apps to directly start your activity with a certain kind of intent.

What is the difference between MIME type and extension?

Whereas file extensions are commonly used for your OS to decide what program to open a file with, Mime types are used by your browser to decide how to present some data (or the server on how to interpret received data).

What is the MIME type of a file?

A media type (also known as a MIME type) is a two-part identifier for file formats and format contents transmitted on the Internet. The Internet Assigned Numbers Authority (IANA) is the official authority for the standardization and publication of these classifications.


1 Answers

afaik, that would rather be like that (one filter with the various values):

 <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="application/vnd.ms-xpsdocument"/>
        <data android:mimeType="application/pdf"/>
 </intent-filter>

Also, is it possible that the mime-type is incorrect?

like image 87
njzk2 Avatar answered Dec 22 '22 04:12

njzk2