Multiple file extension/mimetype intent-filters with one activity
Solution 1
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?
Solution 2
Multiple <data>
are logical OR and treated separately. So you have one tag with android:scheme
but without android:pathPattern
and one with android:pathPattern
but without a android:host
and so on. So none of the <data>
tags are complete and will do any good.
You should use:
<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"
android:mimeType="*/*"
android:pathPattern=".*\\.cbz"
android:host="*"
></data>
</intent-filter>
You can have a second <data>
but it would need all four attributes again as all four attributes are mandatory with Android 4 if you want to use android:pathPattern
. (They weren't with older Android versions)
Robin Watts
Updated on June 30, 2022Comments
-
Robin Watts about 2 years
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
-
Martin over 10 yearsInteresting. I once tried to combine
android:mimeType
andandroid:pathPattern
and that did not work. -
Martin over 10 yearsFor
android:pathPattern
all four attributes of the<data>
tag need to be set in Android 4. So your hint won't help the OP. -
madan V about 9 yearsHi Martin if i use the above intent filter, My app is showing when i tried to open gmail app from notification.
-
IgorGanapolsky almost 7 yearsCombining multiple <data> tags works? It only detects the first one for me.