Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Intent Filter for custom file type

Problem

I have a zip file but with a custom file extension xyz. I want my app to be able to open ONLY files with the custom file extension xyz from:

  • Gmail,
  • Open with from the android file explorer,
  • Share via from the android file explorer.

What I have already tried

My best shot was to just use a mime type of application/zip. However this would also open files with the file extension .zip.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:mimeType="application/zip" />
</intent-filter>

I tried to add a <data android:pathPattern=".*\\.xyz"/>. But the problem with this is, that it will be ignored as long as I don't specify android:scheme and android:host see here.

This attribute is meaningful only if the scheme and host attributes are also specified for the filter.

As soon as I specify the scheme and host as seen in the next code segment, I can't even open any file with my App:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <data android:host="*" />
    <data android:scheme="*" />
    <data android:mimeType="application/zip" />
    <data android:pathPattern=".*\\.xyz"/>
</intent-filter>

Possible Duplicates:

  • Android intent filter: associate app with file extension
  • android how to open external file with my application
like image 213
Markus Avatar asked Jul 31 '26 09:07

Markus


1 Answers

Use application/octet-stream instead of application/zip. Bellow works for me:

<intent-filter tools:ignore="AppLinkUrlError"
               android:icon="@mipmap/ic_launcher"
               android:label="@string/app_name"
               android:priority="50" >
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <data android:scheme="file" />
  <data android:scheme="content" />
  <data android:mimeType="application/octet-stream" />
  <data android:pathPattern=".*\\.ext" />
  <data android:pathPattern=".*\\..*\\.ext" />
  <data android:pathPattern=".*\\..*\\..*\\.ext" />
</intent-filter>
like image 140
Michael Kazarian Avatar answered Aug 02 '26 00:08

Michael Kazarian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!